home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / DVIM72-Mac 1.9.6 / source / prtpage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-14  |  8.6 KB  |  371 lines  |  [TEXT/R*ch]

  1. #define JDEB 0
  2. #include "dvihead.h"
  3. #include "commands.h"
  4. #include "gendefs.h"
  5. #include "gblprocs.h"
  6. #include "egblvars.h"
  7. #include "m72.h"
  8. #include "mac-specific.h"
  9. #include "Scale_rect.h"
  10. #include "Copy_banded.h"
  11.  
  12. void rollbeachball( void );
  13. /**********************************************************************/
  14. /****************************** prtpage *******************************/
  15. /**********************************************************************/
  16.  
  17. void
  18. prtpage(bytepos)        /* print page whose BOP is at bytepos */
  19. long bytepos;
  20.  
  21. {
  22.     struct stack_entry
  23.     {
  24.         INT32 h;
  25.         COORDINATE hh;
  26.         INT32 v;
  27.         COORDINATE vv;
  28.         INT32 w, x, y, z;    /* what's on stack */
  29.     };
  30.     register BYTE command;  /* current command                */
  31.     register INT16 i;        /* command parameter; loop index        */
  32.     char tc;            /* temporary character            */
  33.     UNSIGN32 ht_rule;        /* rule height                              */
  34.     UNSIGN32 wd_rule;        /* rule width                               */
  35.     INT32 k,m;            /* temporary parameter            */
  36.     BOOLEAN seen_bop;        /* flag for noting processing of BOP    */
  37.     register INT16 sp;        /* stack pointer                */
  38.     struct stack_entry stack[STACKSIZE];    /* stack            */
  39.     char specstr[MAXSPECIAL+1];        /* \special{} string        */
  40.     INT32 w;            /* current horizontal spacing        */
  41.     INT32 x;            /* current horizontal spacing        */
  42.     INT32 y;            /* current vertical spacing            */
  43.     INT32 z;            /* current vertical spacing            */
  44.  
  45.     Rect    dest, print_dest, preview_dest;
  46.     
  47.     if (g_draw_offscreen)
  48.     {
  49.         SetPort( &g_offscreen_GrafPort );
  50.         EraseRect( &g_offscreen_GrafPort.portRect );
  51.     }
  52.     else
  53.     {
  54.         SetPort( g_page_window );
  55.         EraseRect( &g_page_window->portRect );
  56.     }
  57.     SetPort( (GrafPtr) g_print_port_p );
  58.     PrOpenPage( g_print_port_p, nil );
  59.     g_print_status = 3;
  60.     if (PrError() != noErr)
  61.     {
  62.         printf("PrOpenPage error %d.\n", PrError());
  63.         /* (void)fflush(stdout); */
  64.     }
  65.     (**g_print_rec_h).prJob.pIdleProc = (ProcPtr)Printer_idle;
  66.     if (!g_draw_offscreen)
  67.         Set_pic_procs();
  68.     if ((**g_print_rec_h).prStl.feed == feedCut) /* refresh cancel dialog */
  69.     {
  70.         DrawDialog( g_cancel_dialog );
  71.         SetPort( (GrafPtr) g_print_port_p );
  72.     }
  73.     if ((**g_print_rec_h).prJob.bJDocLoop == bSpoolLoop)
  74.         /* Tell the ImageWriter driver not to */
  75.         PicComment(1000, 0, nil);    /* ..."thin the bits" */
  76.  
  77. /***********************************************************************
  78. Process all commands  between the  BOP at bytepos  and the  next BOP  or
  79. POST.  The page is  printed when the  EOP is met,  but font changes  can
  80. also happen between EOP and BOP, so we have to keep going after EOP.
  81. ***********************************************************************/
  82.  
  83.     seen_bop = FALSE;            /* this is first time through */
  84.     (void) FSEEK(dvifp,bytepos,0);    /* start at the desired position */
  85.  
  86.     for (;;)    /* "infinite" loop - exits when POST or second BOP met */
  87.     {
  88. #if OS_THINKC
  89.         if (User_wants_out())
  90.             return;
  91. #endif /* OS_THINKC */
  92.     command = (BYTE)nosignex(dvifp,(BYTE)1);
  93.     rollbeachball(); /* OS_THINKC */
  94.     switch (command)
  95.     {
  96.  
  97.     case SET1:
  98.     case SET2:
  99.     case SET3:
  100.     case SET4:
  101.         (void)setchar((BYTE)nosignex(dvifp,(BYTE)(command-SET1+1)),TRUE);
  102.         break;
  103.  
  104.     case SET_RULE:
  105.         ht_rule = nosignex(dvifp,(BYTE)4);
  106.         wd_rule = nosignex(dvifp,(BYTE)4);
  107.         (void)setrule(ht_rule,wd_rule,TRUE);
  108.         break;
  109.  
  110.     case PUT1:
  111.     case PUT2:
  112.     case PUT3:
  113.     case PUT4:
  114.         (void)setchar((BYTE)nosignex(dvifp,(BYTE)(command-PUT1+1)),FALSE);
  115.         break;
  116.  
  117.     case PUT_RULE:
  118.         ht_rule = nosignex(dvifp,(BYTE)4);
  119.         wd_rule = nosignex(dvifp,(BYTE)4);
  120.         (void)setrule(ht_rule,wd_rule,FALSE);
  121.         break;
  122.  
  123.     case NOP:
  124.         break;
  125.  
  126.     case BOP:
  127.         if (seen_bop)
  128.             goto close_page;            /* we have been here already */
  129.         seen_bop = TRUE;
  130.  
  131.         for (i=0; i<=9; i++)
  132.         tex_counter[i] = (INT32)signex(dvifp,(BYTE)4);
  133.  
  134.         if (!quiet)
  135.         {
  136.             (void)printf("{%s}",tctos()); /* TeX page counters */
  137.             /* (void) fflush(stderr); */
  138.         }
  139.         (void) nosignex(dvifp,(BYTE)4);    /* skip prev. page ptr */
  140.  
  141.         hxxxx = vxxxx = w = x = y = z = 0;
  142.         hh = lmargin;
  143.         vv = tmargin;
  144.         sp = 0;
  145.         fontptr = (struct font_entry*)NULL;
  146.         break;
  147.  
  148.     case EOP:
  149.  
  150.         goto close_page;
  151.  
  152.     case PUSH:
  153.         if (sp >= STACKSIZE)
  154.         {
  155.             Kill_dvi("prtpage():  stack overflow");
  156.             return;
  157.         }
  158.         stack[sp].h = hxxxx;
  159.         stack[sp].hh = hh;
  160.         stack[sp].v = vxxxx;
  161.         stack[sp].vv = vv;
  162.         stack[sp].w = w;
  163.         stack[sp].x = x;
  164.         stack[sp].y = y;
  165.         stack[sp].z = z;
  166.         sp++;
  167.         break;
  168.  
  169.     case POP:
  170.         --sp;
  171.         if (sp < 0)
  172.         {
  173.             Kill_dvi("prtpage():  stack underflow");
  174.             return;
  175.         }
  176.         hxxxx = stack[sp].h;
  177.         hh = stack[sp].hh;
  178.         vxxxx = stack[sp].v;
  179.         vv = stack[sp].vv;
  180.         w = stack[sp].w;
  181.         x = stack[sp].x;
  182.         y = stack[sp].y;
  183.         z = stack[sp].z;
  184.         break;
  185.  
  186.     case RIGHT1:
  187.     case RIGHT2:
  188.     case RIGHT3:
  189.     case RIGHT4:
  190.         (void)moveover(signex(dvifp,(BYTE)(command-RIGHT1+1)));
  191.         break;
  192.  
  193.     case W0:
  194.         (void)moveover(w);
  195.         break;
  196.  
  197.     case W1:
  198.     case W2:
  199.     case W3:
  200.     case W4:
  201.         w = (INT32)signex(dvifp,(BYTE)(command-W1+1));
  202.         (void)moveover(w);
  203.         break;
  204.  
  205.     case X0:
  206.         (void)moveover(x);
  207.         break;
  208.  
  209.     case X1:
  210.     case X2:
  211.     case X3:
  212.     case X4:
  213.         x = (INT32)signex(dvifp,(BYTE)(command-X1+1));
  214.         (void)moveover(x);
  215.         break;
  216.  
  217.     case DOWN1:
  218.     case DOWN2:
  219.     case DOWN3:
  220.     case DOWN4:
  221.         (void)movedown(signex(dvifp,(BYTE)(command-DOWN1+1)));
  222.         break;
  223.  
  224.     case Y0:
  225.         (void)movedown(y);
  226.         break;
  227.  
  228.     case Y1:
  229.     case Y2:
  230.     case Y3:
  231.     case Y4:
  232.         y = signex(dvifp,(BYTE)(command-Y1+1));
  233.         (void)movedown(y);
  234.         break;
  235.  
  236.     case Z0:
  237.         (void)movedown(z);
  238.         break;
  239.  
  240.     case Z1:
  241.     case Z2:
  242.     case Z3:
  243.     case Z4:
  244.         z = signex(dvifp,(BYTE)(command-Z1+1));
  245.         (void)movedown(z);
  246.         break;
  247.  
  248.     case FNT1:
  249.     case FNT2:
  250.     case FNT3:
  251.     case FNT4:
  252.         (void)setfntnm((INT32)nosignex(dvifp,
  253.         (BYTE)(command-FNT1+1)));
  254.         if (g_abort_dvi)
  255.             return;
  256.         break;
  257.  
  258.     case XXX1:
  259.     case XXX2:
  260.     case XXX3:
  261.     case XXX4:
  262.         k = (INT32)nosignex(dvifp,(BYTE)(command-XXX1+1));
  263.         if (k > MAXSPECIAL)
  264.         {
  265.         (void)sprintf(message,
  266.             "prtpage():  \\special{} string of %d characters longer \
  267. than DVI driver limit of %d -- truncated.",
  268.         k,MAXSPECIAL);
  269.         (void)warning(message);
  270.         }
  271.         m = 0;
  272.         while (k--)
  273.         {
  274.          tc = (char)nosignex(dvifp,(BYTE)1);
  275.          if (m < MAXSPECIAL)
  276.              specstr[m++] = tc;
  277.         }
  278.         specstr[m] = '\0';
  279.          (void) special(specstr);
  280.          /* a PICT might turn off our picture comment? */
  281.         if ((**g_print_rec_h).prJob.bJDocLoop == bSpoolLoop)
  282.             /* Tell the ImageWriter driver not to */
  283.             PicComment(1000, 0, nil);    /* ..."thin the bits" */
  284.         break;
  285.  
  286.     case FNT_DEF1:
  287.     case FNT_DEF2:
  288.     case FNT_DEF3:
  289.     case FNT_DEF4:
  290.         if (preload)
  291.         (void)skipfont ((INT32) nosignex(dvifp,
  292.             (BYTE)(command-FNT_DEF1+1)));
  293.         else
  294.         (void)readfont ((INT32) nosignex(dvifp,
  295.             (BYTE)(command-FNT_DEF1+1)));
  296.         break;
  297.  
  298.     case PRE:
  299.         Kill_dvi("prtpage():  PRE occurs within file");
  300.         return;
  301.  
  302.     case POST:
  303.         goto close_page;
  304. #if NOTNOW    /* Should this stuff ever happen? */
  305.         (void)dviterm();        /* terminate DVI file processing */
  306.         (void)Close_printer();        /* terminate device output */
  307.         (void)alldone();        /* this will never return */
  308. #endif
  309.         break;
  310.  
  311.     case POST_POST:
  312.         Kill_dvi("prtpage():  POST_POST with no preceding POST");
  313.         return;
  314.  
  315.     default:
  316.         if (command >= FONT_00 && command <= FONT_63)
  317.         {
  318.             (void)setfntnm((INT32)(command - FONT_00));
  319.             if (g_abort_dvi)
  320.                 return;
  321.         }
  322.         else if (command >= SETC_000 && command <= SETC_127)
  323.  
  324. #if    (HPJETPLUS | POSTSCRIPT | IMPRESS | CANON_A2)
  325.         (void)setstr((BYTE)command); /* this sets several chars */
  326. #else
  327.         (void)setchar((BYTE)(command-SETC_000), TRUE);
  328. #endif /* (HPJETPLUS | POSTSCRIPT | IMPRESS | CANON_A2) */
  329.  
  330.         else
  331.         {
  332.         (void)sprintf(message,"prtpage():  %d is an undefined command",
  333.             command);
  334.             Kill_dvi(message);
  335.             return;
  336.         }
  337.         break;
  338.     }
  339.     }
  340.  
  341. close_page:
  342.     if (g_draw_offscreen)
  343.     {
  344.         
  345.         Scale_rect( &g_offscreen_GrafPort.portRect,
  346.             &print_dest, &preview_dest );
  347.         if (g_preview)
  348.         {
  349.             SetPort( g_page_window );
  350.             /* We use srcCopy instead of srcOr here for speed. */
  351.             CopyBits( &g_offscreen_GrafPort.portBits,
  352.                 &g_page_window->portBits,
  353.                 &g_offscreen_GrafPort.portRect,
  354.                 &preview_dest, srcCopy, NIL );
  355.         }
  356.         SetPort( (GrafPtr) g_print_port_p );
  357.         Copy_banded( &g_offscreen_GrafPort.portBits,
  358.             &g_print_port_p->gPort.portBits,
  359.             &g_offscreen_GrafPort.portRect, &print_dest );
  360.     }
  361.     if ((**g_print_rec_h).prJob.bJDocLoop == bSpoolLoop)
  362.         PicComment(1001, 0, nil);
  363.     PrClosePage( g_print_port_p );
  364.     g_print_status = 2;
  365.     if (PrError() != noErr)
  366.     {
  367.         g_abort_dvi = TRUE;
  368.         printf("PrClosePage error %d.\n", PrError());
  369.     }
  370. }
  371.