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 >
Wrap
Text File
|
1993-08-06
|
34KB
|
1,082 lines
/************************************************************************/
/* Filename: DVIMGR.C */
/* Function: Program to view TeX DVI ouput file in a MGR-Windows Envir- */
/* onment under OS-9/68k. */
/* */
/* This version is based on the DEC-Windows version from: */
/*----------------------------------------------------------------------*/
/* (c) 1990 by Christian MARKUS, Fachbereich Informatik, */
/* Schlueterstr. 70, D 2000 Hamburg 13, Fed.Rep.of Germany */
/* */
/* EMAIL : via friesland@rz.informatik.uni-hamburg.dbp.de */
/*----------------------------------------------------------------------*/
/* */
/* Adapted to OS-9/68k and the MGR window environment: */
/* (c) 1993 by */
/*-----------------------------+----------------------------------------*/
/* Lars-Christian Schulze | Institute for Communications Technology*/
/* | at the */
/* Internet: (preferred) | Braunschweig Technical University */
/* schulze@ifn.ing.tu-bs.de | */
/* | Schleinitzstr. 23 */
/* I7100401@dbstu1.rz.tu-bs.de | 38092 Braunschweig */
/* Voice: +49 531 391 2455 | Germany */
/*-----------------------------+----------------------------------------*/
/* */
/* Program History: */
/* */
/* Ver#: ! Date: !Comment: !Author: */
/* ------+--------+-------------------------------------+-------------- */
/* 1.0 !04.07.89!First version !Ch. Markus */
/* 1.1 !09.03.90!Corrected and updated !Ch. Markus */
/* !- get/set bit/byte order correctly ! */
/* !- one window/automatically adjusted ! */
/* !- window size can be changed ! */
/* !- Scrollbars available ! */
/* !- Title contains info ! */
/* !- Copy to Clipboard ! */
/* 1.2 !19.06.90!- adaption for ANSI-C/VAX-C 3.1 !Ch. Markus */
/*----------------------------------------------------------------------*/
/* Program description: */
/* */
/* This driver works in a DECWindows environment and is based on TEX */
/* DVI-driver family developed by N.Beebe, Utah, USA. The include files */
/* are taken from version 2.10, the driver DVIDECW is based on the */
/* DVIBIT driver. Instead of using download fonts it creates a bitmap */
/* (similar to DVIJET) and displays it in the output window upon a */
/* window exposure event. Upon each interactive command, the bitmap is */
/* created again. */
/*----------------------------------------------------------------------*/
/* Installation guide: */
/* */
/* - modify the TEXVIEW.COM file to suit your system's paths */
/* - in FileView, select the Customize/Verbs and Menus option */
/* - enter a new verb name 'TeX Preview' below the verb names box and */
/* click on enter button upon completition */
/* - enter the DCL command for the 'Tex Preview' verb, that is entering */
/* somewhat like @<path>texview.com and clicking on the 'enter' button*/
/* - select a menu from the 'Menu Names' box and click on the 'Add' */
/* button below the 'Verbs in Menu' list box. */
/* - press 'Apply' and 'Ok' button to install new item in menu bar */
/* - select the Customize/File Types option and install the .DVI file */
/* type. */
/*----------------------------------------------------------------------*/
/* Quick guide to operations: */
/* */
/* Invoke DVIDecw in four different ways: */
/* - from a DECTerm terminal window */
/* -> just type the command,options and filename to be processed */
/* - from the FileView DCL Command window */
/* -> just type the command,options and filename to be processed */
/* - by selecting a FileView menu item (if TEXVIEW.COM is installed) */
/* -> a dialog box pops up asking for a filename, a second box will */
/* ask for any processing parameters */
/* - by double-clicking on any .DVI file (if TEXVIEW.COM is installed */
/* and the File Types box is set for .DVI files */
/* -> a dialog box pops up asking for processing parameters */
/* */
/* All options of DVIBIT are accepted, but the -o option (order pages) */
/* is ignored, DVIDecw will only pick the first selected page */
/* The program will create a command and an output window and display */
/* the first selected page. */
/* All interactive commands can be selected from menus and should be */
/* easy to understand. */
/* If the TeX Preview window has the 'Input focus' key equivalents */
/* provide a shortcut for some menu commands. To set the input focus, */
/* just click into the Tex Preview window, the window title will change */
/* to the highlight color. */
/*----------------------------------------------------------------------*/
/* The following files taken from the original BEEBE driver have been */
/* modified (using #if compiler switches) for DECWINDOWS: */
/* */
/* DISPCHAR.H -> make up for reversed Y-coordinate origin */
/* DVIFILE.H -> change program structure to event-driven calls */
/* FATAL.H -> don't perform resetterm() function in DECW environment */
/* GBLPROCS.H -> modifications to conform with ANSI-C (Vax C 3.1) */
/* MACHDEFS.H -> changed FONTPATH, FONTLIST and DVIHELP for OS_VMS */
/* OPENFONT.H -> allow open files according to MAXOPEN,quota and avail. */
/* PRTPAGE.H -> changes in EOP case and keyboard status request */
/* SETCHAR.H -> make up for reversed Y-coordinate origin */
/* SETRULE.H -> make up for reversed Y-coordinate origin */
/*----------------------------------------------------------------------*/
/* The DVIDecw package contains the files listed below: */
/* */
/* DVIDOC_D.DVI Installation/User's Guide in GERMAN */
/* DVIDOC_E.DVI Installation/User's Guide in ENGLISH */
/* DVIDECW.C Main C source code, all DECWindows specific coding */
/* DVIDECW.UIL User Interface description file */
/* DVIDECW.COM Compile,UIL and link command procedure */
/* DVILINK.COM Link DVIDECW for other VMS versions */
/* TEXVIEW.COM Command procedure for FileView invocation of DVIDECW */
/* xxxxxxx.H Include files (listed above) modified for DVIDECW */
/************************************************************************/
#include <stdio.h> /* Standard definitions */
/************************************************************************/
/* MGR definitions */
/************************************************************************/
#include "/h0/mgr/defs/term.h"
#include "/h0/mgr/defs/window.h"
char *_FGETS(char *, int, FILE *);
#undef BLACK
#undef WHITE
#define APP_ID "TeX Preview" /* Application name */
#define CLPBRD_FORMAT "XYBitmap" /* Clipboard data format */
/*----------------------------------------------------------------------*/
/* Constants for different actions. */
/*----------------------------------------------------------------------*/
#define k_top_margin 'a'
#define k_backward 'b'
#define k_curs_down_me 'd'
#define k_reload_fonts 'e'
#define k_forward 'f'
#define k_gotopage_me 'g'
#define k_auto_reshape 'h'
#define k_curs_left_me 'l'
#define k_left_margin 'm'
#define k_nextpage_me 'n'
#define k_bot_page_me 'o'
#define k_prevpage_me 'p'
#define k_curs_right_me 'r'
#define k_top_page_me 't'
#define k_curs_up_me 'u'
#define k_redraw 'w'
#define k_quit_me 'x'
#define k_reset_pos_me 'y'
#define k_SHAPEREQ 'H'
#define k_DESTROY 'Y'
#define k_zoom_in_me '+'
#define k_zoom_out_me '-'
#define k_move_speed_x '('
#define k_move_speed_y ')'
#define k_zoom0 '0'
#define k_zoom1 '1'
#define k_zoom2 '2'
#define k_zoom3 '3'
#define k_zoom4 '4'
#define k_zoom5 '5'
/*----------------------------------------------------------------------*/
/* Global data declarations */
/*----------------------------------------------------------------------*/
static int x_windsize; /* Window workarea size in pixel*/
static int y_windsize;
static int xwindow, /* Top left corner coordinates of */
ywindow; /* displayed part of TeX page. */
/* Always equal to xscreen and yscreen. */
static int x_pagesize; /* Virtual page size in pixel */
static int y_pagesize;
static int x_maxwsize = 850, /* Max. window size. */
y_maxwsize = 650,
x_mag0wins = -1, /* Max. window for magstep0. */
y_mag0wins = -1;
static int auto_reshape = 1; /* do automatic reshape when
changing magnification. */
static int x_step_size = 5; /* current step width for moves */
static int y_step_size = 90; /* in % of window size. */
static int TeX_win; /* Output window alternate ID. */
static int base_mag, /* Base magnification for zooming */
run_magstep = 0; /* Runtime magstep. */
struct menu_entry zoom_menu[] = {
"magstep 0", "\1770\n",
"magstep 1", "\1771\n",
"magstep 2", "\1772\n",
"magstep 3", "\1773\n",
"magstep 4", "\1774\n",
"magstep 5", "\1775\n"
};
struct menu_entry stepsize_menu[] = {
" 5 % ", "5\n",
" 10 % ", "10\n",
" 15 % ", "15\n",
" 20 % ", "20\n",
" 30 % ", "30\n",
" 50 % ", "50\n",
" 75 % ", "75\n",
" 90 % ", "90\n",
"100 % ", "100\n"
};
struct menu_entry step_menu[] = {
"step down", "\177d\n",
"step up", "\177u\n",
"step right", "\177r\n",
"step left", "\177l\n",
"x stepsize >>> ", "\177(",
"y stepsize >>> ", "\177)"
};
struct menu_entry main_menu[] = {
"forward", "\177f\n",
"backward", "\177b\n",
"next page", "\177n\n",
"prev page", "\177p\n",
"go to page ... ", "\177g\n",
"steps >>> ", "",
"-----------------", "",
"zoom in", "\177+\n",
"zoom out", "\177-\n",
"set zoom >>> ", "",
"redraw", "\177w\n",
"auto reshape", "\177h\n",
"-----------------", "",
"top of page", "\177t\n",
"bottom of page ", "\177o\n",
"top left of page", "\177y\n",
"-----------------", "",
"tgl. top margin", "\177a\n",
"tgl. left margin", "\177m\n",
"reload fonts", "\177e\n",
"-----------------", "",
"exit", "\177x\n"
};
/*----------------------------------------------------------------------*/
/* forward declaration of some routines. */
/*----------------------------------------------------------------------*/
static void prtbmap(void);
static void w_print(int line,char *string);
static void clrbmap(void);
static void redraw(void);
static void mgr_main_loop( void);
static void read_dvimgrinit(int *, int *, int *, int*, int*);
void calculate_windsize( void);
void get_windowdata( struct window_data *pwd, int winid);
/************************************************************************/
/* DVI-BEEBE driver definitions */
/************************************************************************/
#include <dvihead.h>
/*----------------------------------------------------------------------*/
/* Device specific definitions */
/*----------------------------------------------------------------------*/
#define DECWINDOWS 1 /* cond. compilations flag */
#define BBNBITGRAPH 1 /* BITGRAPH driver as base */
#define OSK_MGR
#define VERSION_NO "2.10, (MGR/OSK Version 1.00)"
/*DVI driver version number*/
#define DEVICE_ID "DVI MGR 69 dpi"
/* String printed at runtime */
#define OUTFILE_EXT "OSK" /* Not used here (dummy) */
#define BYTE_SIZE 8 /* Not used here (dummy) */
/*----------------------------------------------------------------------*/
/* These constants are special to DVIBIT and are not req. by DVIDECW */
/*----------------------------------------------------------------------*/
#define FIRSTBGCHAR 32
#define LASTBGCHAR 127
#define NBGFONTS 3
/*----------------------------------------------------------------------*/
/* Page dimension definition */
/* Bitmap window size: 10" * 8" or 830 * 664 pixel (83 dpi) */
/* Bitmap window size: 12" * 9" or 828 * 621 pixel (69 dpi) */
/*----------------------------------------------------------------------*/
#define XDPI 69 /* horizontal dots/inch */
#define XPSIZE 13 /* horizontal screen size in " */
#define XMAG0PSIZE 9 /* mag0 horizontal page size (lcs) */
#define XSIZE (((XDPI*XPSIZE+2*HOST_WORD_SIZE-1)/\
(2*HOST_WORD_SIZE))*(2*HOST_WORD_SIZE))
#define XWORDS ((XSIZE + HOST_WORD_SIZE -1)/HOST_WORD_SIZE)
#define YDPI 69 /* vertical dots/inch */
#define YPSIZE 17 /* vertical screen size in inch */
#define YMAG0PSIZE 12 /* mag0 vertical page size (lcs) */
#define YSIZE (YDPI*YPSIZE) /* number vertical pixel */
#define XBIT ((1+2*XWORDS)/2) /* Printer bitmap (even col) */
#define YBIT YSIZE
#define MIN_DPI 69 /* Lowest resolution to display */
#define MAX_DPI 144 /* Highest res. to display */
/* not used */
#define MIN_MAGSTEP 0
#define MAX_MAGSTEP 5
/*----------------------------------------------------------------------*/
/* General definitions superseeding previous definitions */
/*----------------------------------------------------------------------*/
#undef STDRES /* 0 for low resolution device */
#define STDRES 0
/*----------------------------------------------------------------------*/
/* Coding starts here... */
/*----------------------------------------------------------------------*/
#include <bitmap.h> /* Bitmap definitions */
#include <main.h>
#if DECWINDOWS /* redefine STDMAG previously */
#undef STDMAG /* define in MAIN.H */
#if STDRES
#define STDMAG 500
#else /* STDMAG = dpi * 5 */
#define STDMAG 347 /* 83 dpi : STDMAG = 417 */
/* 69 dpi : STDMAG = 347 */
#endif /* STDRES */
#endif /* DECWINDOWS */
#include <abortrun.h>
#include <actfact.h>
#include <alldone.h>
/*----------------------------------------------------------------------*/
/* BOPACT begin of page actions */
/*----------------------------------------------------------------------*/
void bopact()
{
(void)clrbmap(); /* Clear bitmap memory */
pbghpos = pbgvpos = -99; /* set global values */
cpagep = (long)FTELL(dvifp) -1L;
ppagep = (long)nosignex(dvifp,(BYTE)4);
}
#include <chargf.h>
#include <charpk.h>
#include <charpxl.h>
#include <clrbmap.h>
#include <clrrow.h>
#include <dbgopen.h>
/*----------------------------------------------------------------------*/
/* DEVINIT initialize MGR evironment. */
/*----------------------------------------------------------------------*/
void devinit(argc,argv)
int argc; /* Command line argument count. */
char *argv[]; /* Pointers to command line args*/
{
int ft = 1, /* Foreground text color. */
bt = 0, /* Background text color. */
f = 0, /* Foreground color. */
b = 1, /* Background color. */
font = 8; /* Window font number. */
int x = 0, y = 0; /* Initial position of TeX window. */
struct window_data wd; /* To hold window parameters. */
ckmgrterm(NULL); /* Check if we're running in a */
/* MGR environment. */
/* Setup the MGR library. */
m_setup(M_FLUSH); /* flush() after each outpout. */
m_push(P_ALL & ~P_WINDOW); /* Push old window status. */
m_ttyset();
/* Read init file. */
(void)read_dvimgrinit(&ft, &bt, &font, &f, &b);
/* Open TeX window centered around main window.*/
get_windowdata(&wd, 0);
calculate_windsize();
x = wd.x + (wd.w - x_windsize) / 2;
y = wd.y + (wd.h - y_windsize) / 2;
if (x<0) x=0;
if (y<0) y=0;
TeX_win = m_makewindowfcol(x, y, x_windsize, y_windsize, font, f, b);
get_windowdata(&wd, TeX_win);
x_windsize = wd.w;
y_windsize = wd.h;
m_selectwin(TeX_win);
m_setmode(M_ABS);
m_setmode(M_FIXBDRCOL);
m_setmode(M_SHAPEREQ);
m_fcolor(ft);
m_bcolor(bt);
m_setcursor(CS_NONE);
m_setevent(CHARACTER, "\177%x\n");
m_setevent(RESHAPE, "\177H%a\n");
m_setevent(DESTROY, "\177Y %w\n");
menu_load(1, MENU_SIZE(main_menu), main_menu);
menu_load(2, MENU_SIZE(step_menu), step_menu);
menu_load(3, MENU_SIZE(stepsize_menu), stepsize_menu);
menu_load(4, MENU_SIZE(zoom_menu), zoom_menu);
m_linkmenu(1, 5, 2, MF_AUTO);
m_linkmenu(2, 4, 3, MF_AUTO);
m_linkmenu(2, 5, 3, MF_AUTO);
m_linkmenu(1, 9, 4, MF_AUTO);
m_selectmenu(1);
m_selectwin(0);
m_setmode(M_ACTIVATE);
base_mag = runmag;
if (run_magstep != 0) {
set_magstep(run_magstep);
}
xscreen = 0; /* Set initial values. */
yscreen = 0;
xwindow = 0;
ywindow = 0;
(void)getbmap(); /* Allocate bitmap memory */
}
void get_windowdata( struct window_data *pwd, int winid)
{
struct window_data wd2;
int rval;
do {
rval = get_eachclientwin(&wd2);
if (wd2.num == winid) {
*pwd = wd2;
}
} while (rval != 0);
return;
}
/*----------------------------------------------------------------------*/
/* Read configuration file for fonts and colors. */
/* First look in the current directory, then in /dd/sys, then in */
/* /h0/sys. If no file could be found we use the default values. */
/*----------------------------------------------------------------------*/
static char *paramnames[] = {
"font", /* 0 */
"fgcolor", /* 1 */
"bgcolor", /* 2 */
"text-fgcolor", /* 3 */
"text-bgcolor", /* 4 */
"startmag", /* 5 */
"x_maxwsize", /* 6 */
"y_maxwsize", /* 7 */
"x_mag0wins", /* 8 */
"y_mag0wins", /* 9 */
"x_step_size", /* 10 */
"y_step_size", /* 11 */
NULL
};
static void read_dvimgrinit(int *pft, int *pbt, int *pfont, int *pf, int *pb)
{
FILE *fp;
char cline[80],
cpname[32];
int i, value;
fp = FOPEN(".dvimgrinit", "r");
DEBUG_OPEN(fp, ".dvimgrinit", "r");
if (fp == (FILE*)NULL)
{
fp = FOPEN("/dd/sys/.dvimgrinit", "r");
DEBUG_OPEN(fp, "/dd/sys/.dvimgrinit", "r");
if (fp == (FILE*)NULL)
{
fp = FOPEN("/h0/sys/.dvimgrinit", "r");
DEBUG_OPEN(fp, "/h0/sys/.dvimgrinit", "r");
if (fp == (FILE*)NULL) {
return;
}
}
}
while (fgets(cline, 80, fp) != NULL)
{
if (cline[0] == ';' || cline[0] == '*' || cline[0] == '\n') {
continue;
}
sscanf(cline, "%s %d", &cpname, &value);
for (i = 0; paramnames[i] != NULL; i++) {
if (strcmp(paramnames[i], cpname) == 0) {
break;
}
}
switch(i)
{
case 0: *pfont = value; break;
case 1: *pf = value; break;
case 2: *pb = value; break;
case 3: *pft = value; break;
case 4: *pbt = value; break;
case 5: run_magstep = value; break;
case 6: x_maxwsize = value; break;
case 7: y_maxwsize = value; break;
case 8: x_mag0wins = value; break;
case 9: y_mag0wins = value; break;
case 10: x_step_size = value; break;
case 11: y_step_size = value; break;
default:
fprintf(stderr,
"Unknown parameter in config file: %s\n", cpname);
}
}
fclose (fp);
return;
}
/*----------------------------------------------------------------------*/
/* DEVTERM terminate DEC Windows output */
/*----------------------------------------------------------------------*/
void devterm()
{ /* Terminate output window */
m_selectwin(TeX_win);
m_clearevent(CHARACTER);
m_clearevent(RESHAPE);
m_clearevent(DESTROY);
m_clearmode(M_SHAPEREQ);
m_clearmenu(1);
m_selectwin(0);
m_destroywin(TeX_win);
m_popall();
m_flush();
}
#include <dispchar.h>
#include <dvifile.h>
#include <dviinit.h>
#include <dviterm.h>
#include <f20open.h>
#include <fatal.h>
#include <fillrect.h>
#include <findpost.h>
#include <fixpos.h>
#include <fontfile.h>
#include <fontsub.h>
#include <getbmap.h>
#include <getbytes.h>
#include <getfntdf.h>
#include <getpgtab.h>
#include <inch.h>
#include <initglob.h>
#include <loadchar.h>
#include <movedown.h>
#include <moveover.h>
#include <moveto.h>
/*----------------------------------------------------------------------*/
/* NEWFONT dummy routine called from readxx routines */
/*----------------------------------------------------------------------*/
void newfont()
{
}
#include <nosignex.h>
#include <openfont.h>
#include <option.h>
/*----------------------------------------------------------------------*/
/* PRTBMAP display created bitmap in output window */
/*----------------------------------------------------------------------*/
void prtbmap() /* 25-Jun-1993 lcs */
{ /* Copy bitmap to window */
int y;
UNSIGN32 *p;
m_selectwin(TeX_win); /* Select output window. */
m_setmode(M_ACTIVATE);
p = bitmap;
for (y = 0; y < y_windsize && y < y_pagesize; y++)
{
m_bitloadcol(0, y, x_windsize, 1, 1, p);
p += XWORDS;
}
/* m_bitloadcol(0, 0, XSIZE, YSIZE, 1, p); */
m_selectwin(0); /* Back to main window. */
}
#include <outrow.h>
#include <prtpage.h>
#include <readfont.h>
#include <readgf.h>
#include <readpk.h>
#include <readpost.h>
#include <readpxl.h>
#include <reldfont.h>
#include <rulepxl.h>
#include <setchar.h>
#include <setfntnm.h>
#include <setrule.h>
#include <signex.h>
#include <skgfspec.h>
#include <skipfont.h>
#include <skpkspec.h>
#include <special.h>
#include <strchr.h>
#include <strcm2.h>
#include <strid2.h>
#include <strrchr.h>
#include <tctos.h>
/*----------------------------------------------------------------------*/
/* UNLOADFONTS mark all fonts as unloaded */
/*----------------------------------------------------------------------*/
void unloadfonts() /* mark all fonts as not loaded */
{ /* and set no current fonts */
INT16 k; /* loop index */
for (fontptr = hfontptr; fontptr != (struct font_entry *)NULL;
fontptr = fontptr->next)
{
for (k = 0; k < NPXLCHARS; ++k)
fontptr->ch[k].isloaded = FALSE;
if (fontptr->font_file_id != (FILE*)NULL)
{
(void)fclose(fontptr->font_file_id);
fontptr->font_file_id = (FILE*)NULL;
}
}
fontfp = (FILE*)NULL; /* no current font file */
for ( ; nopen > 0; --nopen) /* clear font file cache */
{
font_files[nopen].font_id = (FILE*)NULL;
font_files[nopen].use_count = (INT16)0;
}
/* NB: It is important here that the loop index be global; the relation
of fontptr to pfontptr is used by openfont() to decide whether the font
file is already open. */
for (fontptr = hfontptr; fontptr != (struct font_entry *)NULL;
fontptr = fontptr->next)
{
pfontptr = (struct font_entry *)(NULL);
/* so reldfont() calls openfont() */
(void)reldfont(fontptr); /* get new font metrics */
}
}
#include <usage.h>
#include <warning.h>
/************************************************************************/
/* Service routines for MGR environment */
/************************************************************************/
/*----------------------------------------------------------------------*/
/* Main loop to handle MGR events. */
/*----------------------------------------------------------------------*/
static void mgr_main_loop( void)
{
int i, value;
char cline[256]; /* Array for MGR event string. */
int new_page_number; /* destination page number */
char *new_page_string; /* page number in string form */
int x, y; /* Window coordinates for reshape. */
struct window_data wd; /* To hold window parameters. */
static BOOLEAN btmargin = TRUE;
static BOOLEAN blmargin = TRUE;
m_sendme("\177t\n"); /* Display first page immediately. */
m_flush();
while(m_getevent(cline, sizeof(cline)) != NULL) /* Wait for MGR event. */
{ /* We'll never leave this loop. */
if (cline[0] != '\177') {
continue;
}
switch (cline[1])
{
case k_SHAPEREQ:
sscanf(&cline[2],"%d %d %d %d", &x, &y, &x_windsize, &y_windsize);
m_selectwin(TeX_win);
m_shapewindow(x, y, x_windsize, y_windsize);
m_selectwin(0);
auto_reshape = FALSE;
redraw();
break;
case k_auto_reshape:
auto_reshape = TRUE;
get_windowdata(&wd, 0);
calculate_windsize();
x = wd.x + (wd.w - x_windsize) / 2;
y = wd.y + (wd.h - y_windsize) / 2;
if (x<0) x=0;
if (y<0) y=0;
m_selectwin(TeX_win);
m_shapewindow(x, y, x_windsize, y_windsize);
get_windowdata(&wd, TeX_win);
x_windsize = wd.w;
y_windsize = wd.h;
break;
case k_redraw:
redraw();
break;
case k_prevpage_me: /* goto previous page (if avail)*/
if(cur_index > 0)
{
cur_index--;
cur_page_number--;
redraw();
}
else /* first page reached already */
;
break;
case k_nextpage_me: /* goto next page (if avail) */
if(cur_index < page_count-1)
{
cur_index++;
cur_page_number++;
redraw();
}
else /* last page reached already */
;
break;
case k_backward:
if (ywindow == 0) {
if(cur_index > 0) {
cur_index--;
cur_page_number--;
ywindow = y_pagesize - y_windsize;
}
} else {
ywindow -= y_windsize * 3/4;
if (ywindow < 0) {
ywindow = 0;
}
}
redraw();
break;
case k_forward:
if (ywindow == y_pagesize - y_windsize) {
if(cur_index < page_count-1) {
cur_index++;
cur_page_number++;
ywindow = 0;
}
} else {
ywindow += y_windsize * 3/4;
if (ywindow > y_pagesize - y_windsize) {
ywindow = y_pagesize - y_windsize;
}
}
redraw();
break;
case k_bot_page_me: /* goto bottom of page */
ywindow = y_pagesize - y_windsize;
redraw();
break;
case k_top_page_me: /* goto top of page */
ywindow = 0;
redraw();
break;
case k_curs_up_me: /* move up one step */
ywindow -= y_windsize * y_step_size / 100;
redraw();
break;
case k_curs_down_me: /* move down one step */
ywindow += y_windsize * y_step_size / 100;
redraw();
break;
case k_curs_left_me: /* move left one step */
xwindow -= x_windsize * x_step_size / 100;
redraw();
break;
case k_curs_right_me: /* move right one step */
xwindow += x_windsize * x_step_size / 100;
redraw();
break;
case k_gotopage_me: /* Ask for page number to go to. */
new_page_number = 0;
m_selectwin(0);
m_setmode(M_ACTIVATE);
m_clearevent(CHARACTER);
m_ttyreset();
printf("Goto page number: ");
fflush(stdout);
m_gets(cline);
m_ttyset();
m_setevent(CHARACTER, "\177" "C%x\n");
sscanf(cline, "%d", &new_page_number);
if(new_page_number > page_count) {
new_page_number = page_count;
}
if(new_page_number < 1) {
new_page_number = 1;
}
cur_index = new_page_number - 1;
cur_page_number = new_page_number;
ywindow = 0;
redraw();
break;
case k_top_margin: /* toggle use/dont't use topmargin */
if(btmargin == TRUE) {
tmargin = (COORDINATE)(0.1*((float)YDPI));
btmargin = FALSE;
} else {
tmargin = (COORDINATE)(topmargin *((float)YDPI));
btmargin = TRUE;
}
redraw();
break;
case k_left_margin: /* toggle use/dont't use leftmargin */
if(blmargin == TRUE) {
lmargin = (COORDINATE)(0.1*((float)XDPI));
blmargin = FALSE;
} else {
lmargin = (COORDINATE)(leftmargin *((float)XDPI));
blmargin = TRUE;
}
redraw();
break;
case k_move_speed_x: /* set x cursor speed */
{
int i;
i = atol(&cline[2]);
if (i < 0) i = 0;
if (i > 100) i = 100;
x_step_size = i;
}
break;
case k_move_speed_y: /* set y cursor speed */
{
int i;
i = atol(&cline[2]);
if (i < 0) i = 0;
if (i > 100) i = 100;
y_step_size = i;
}
break;
break;
case k_zoom0:
case k_zoom1:
case k_zoom2:
case k_zoom3:
case k_zoom4:
case k_zoom5: /* Set zoom to selected magstep */
{
int i, j; /* Loop variables. */
i = cline[1] - '0';
if (i < MIN_MAGSTEP) i = MIN_MAGSTEP;
if (i > MAX_MAGSTEP) i = MAX_MAGSTEP;
run_magstep = i;
set_magstep( run_magstep);
conv = ((float)num/(float)den) *
((float)runmag/(float)STDMAG) *
#if USEGLOBALMAG
actfact(mag) *
#endif
((float)RESOLUTION/254000.0);
(void)unloadfonts();
redraw();
}
break;
case k_zoom_out_me: /* Zoom down one magstep */
run_magstep--;
if (run_magstep < 0) { /* Constrain resolution range */
run_magstep = 0;
}
set_magstep( run_magstep);
conv = ((float)num/(float)den) *
((float)runmag/(float)STDMAG) *
#if USEGLOBALMAG
actfact(mag) *
#endif
((float)RESOLUTION/254000.0);
(void)unloadfonts();
redraw();
break;
case k_zoom_in_me: /* Zoom up one magstep */
run_magstep++;
if (run_magstep > 5) { /* Constrain resolution range */
run_magstep = 5;
}
set_magstep( run_magstep);
conv = ((float)num/(float)den) *
((float)runmag/(float)STDMAG) *
#if USEGLOBALMAG
actfact(mag) *
#endif
((float)RESOLUTION/254000.0);
(void)unloadfonts();
redraw();
break;
case k_reload_fonts: /* force reloading fonts */
(void)unloadfonts();
redraw();
break;
case k_reset_pos_me: /* reset position after moves */
xwindow = 0;
ywindow = 0;
redraw();
break;
case k_DESTROY:
case k_quit_me: /* Menu File/Quit */
(void)devterm(); /* terminate device output */
(void)dviterm(); /* terminate DVI file processing*/
(void)alldone(); /* this will never return */
break;
default: /* event is unknown */
break;
}
} /* while (m_gets()) */
}
/*----------------------------------------------------------------------*/
/* Redraw the page. */
/*----------------------------------------------------------------------*/
static void redraw( void)
{
char out_string[128]; /* string for messages */
int x_top_windsize;
int y_top_windsize;
/* Constrain view range */
if(xwindow > (x_pagesize - x_windsize))
xwindow = x_pagesize - x_windsize;
if(xwindow < 0)
xwindow = 0;
if(ywindow > (y_pagesize-y_windsize))
ywindow = y_pagesize-y_windsize;
if(ywindow < 0)
ywindow = 0;
xscreen = xwindow;
yscreen = ywindow;
prtpage(page_ptr[cur_index]);
m_selectwin(0);
printf("TeX Preview - Page %d/%d TeX-Page[%s] %d dpi\n",
cur_index+1,page_count,tctos(),(int)((runmag*10/5+5)/10));
prtbmap();
}
int set_magstep(int magstep)
{
int i;
int x, y; /* Initial coordinates of TeX window. */
struct window_data wd;
runmag = base_mag;
for (i = 0; i < magstep; i++) {
runmag=MAGSIZE(actfact((UNSIGN32)((6*runmag)/5)));
}
if (auto_reshape) {
get_windowdata(&wd, 0);
calculate_windsize();
x = wd.x + (wd.w - x_windsize) / 2;
y = wd.y + (wd.h - y_windsize) / 2;
if (x<0) x=0;
if (y<0) y=0;
m_selectwin(TeX_win);
m_shapewindow(x, y, x_windsize, y_windsize);
get_windowdata(&wd, TeX_win);
x_windsize = wd.w;
y_windsize = wd.h;
}
m_selectwin(0);
return(0);
}
void calculate_windsize( void)
{
x_pagesize = (int) ((runmag*10/5+5)/10) * XMAG0PSIZE;
y_pagesize = (int) ((runmag*10/5+5)/10) * YMAG0PSIZE;
if (run_magstep == 0)
{
if (x_mag0wins == -1) {
x_windsize = x_pagesize;
} else {
x_windsize = (x_pagesize > x_mag0wins) ? x_mag0wins : x_pagesize;
}
if (y_mag0wins == -1) {
y_windsize = y_pagesize;
} else {
y_windsize = (y_pagesize > y_mag0wins) ? y_mag0wins : y_pagesize;
}
} else {
x_windsize = (x_pagesize > x_maxwsize) ? x_maxwsize : x_pagesize;
y_windsize = (y_pagesize > y_maxwsize) ? y_maxwsize : y_pagesize;
}
return;
}
/************************************************************************/
/* END of source file */
/************************************************************************/