home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3.4.17 [SPARC, PA-RISC] / nextstep33_risc.iso / NextLibrary / TeX / tex / src / texview / SheetView.m < prev    next >
Encoding:
Text File  |  1992-08-20  |  5.6 KB  |  260 lines

  1. /* Generated by tgr */
  2.  
  3. #import "PageView.h"
  4. #import "SheetView.h"
  5. #import <dpsclient/wraps.h>
  6. #import "TVWindow.h"
  7. #import "dviAccessors.h"
  8. #import <appkit/NXCursor.h>
  9. #import <appkit/Application.h>
  10.  
  11. @implementation SheetView
  12.  
  13. SheetView *myView ;
  14. PageView *myPageView ;
  15.  
  16. extern shalfword hh, vv ;
  17. extern shalfword hhoffset, vvoffset ;
  18. extern shalfword hhmin, hhmax, vvmin, vvmax ;
  19. extern shalfword hhsize, vvsize ;
  20. extern shalfword rhhsize, rvvsize ;
  21. extern shalfword hhmarg, vvmarg ;
  22. extern Boolean orientationset ;
  23. extern Boolean landscape ;
  24. extern Boolean dualpage ;
  25. extern FILE *dvifile ;
  26. extern integer pagenum, seq ;
  27. extern fontdesctype *curfnt ;
  28. extern char realname[] ;
  29. Boolean pagedrawn ;
  30.  
  31. extern id fpageinit() ;
  32. extern void makeraster(), outline() ;
  33. extern void dopage(), error() ;
  34. extern void free(), pagereport() ;
  35. extern void tolandscape() ;
  36. extern void reportname() ;
  37. extern void TPSinit(), TPSselfont(), TPSshow(), TPSQshow(), TPSmoveto() ;
  38. extern void TPShmove(), TPSxshow() ;
  39. extern void fixalertbug() ;
  40. static int offset = 0 ;
  41.  
  42. + newFrame:(const NXRect *)theFrame
  43. {
  44.    NXSize nxs ;
  45.    self = [super newFrame:theFrame];
  46.    nxs.width = mhhsize = 1036 ;
  47.    nxs.height = mvvsize = 1336 ;
  48.    cache = [NXImage newSize:&nxs] ;
  49.    [cache setFlipped:YES] ;
  50.    return self ;
  51. }
  52.  
  53. id makenewdoc(hsize, vsize)
  54. int hsize, vsize ;
  55. {
  56.    return [myView makeNewDoc:hsize:vsize] ;
  57. }
  58.  
  59. - makeNewDoc:(int)hsize:(int)vsize
  60. {
  61.    if (hsize == ohhsize && vsize == ovvsize)
  62.       return 0 ;
  63.    ohhsize = hsize ;
  64.    ovvsize = vsize ;
  65.    [myPageView noScrollUpdates] ;
  66.    [myPageView cachePosition:hsize:vsize] ;
  67.    if (hsize > mhhsize || vsize > mvvsize) {
  68.       NXSize nxs ;
  69.       if (hsize > mhhsize)
  70.          mhhsize = hsize ;
  71.       if (vsize > mvvsize)
  72.          mvvsize = vsize ;
  73.       nxs.width = mhhsize ;
  74.       nxs.height = mvvsize ;
  75.       [cache setSize:&nxs] ;
  76.    }
  77.    offset = mvvsize - vsize ;
  78.    [self sizeTo:hsize:vsize] ;
  79.    [myPageView unCachePosition:hsize:vsize] ;
  80.    [myPageView scrollUpdates] ;
  81.    return self ;
  82. }
  83.  
  84. - update
  85. {
  86.    if ([self needsDisplay])
  87.       [self display] ;
  88.    return(self) ;
  89. }
  90.  
  91. static int dontbother = 1 ;
  92.  
  93. void display()
  94. {
  95.    dontbother = 1 ;
  96.    (void)fpageinit() ;
  97.    dontbother = 0 ;
  98.    [myView display] ;
  99. }
  100.  
  101. - drawSelf:(NXRect *)rects :(int)rectCount
  102. {
  103.     NXRect r ;
  104.     if (dontbother)
  105.        return self ;
  106.     if ((! pagedrawn)) {
  107.        [cache lockFocus] ;
  108. /*   offset = mvvsize - vsize ; should always be true? */
  109.        PStranslate(0, mvvsize - rvvsize) ;
  110. /*     PSsetgray(1.0) ; */
  111.        NX_WIDTH(&r) = rhhsize ;
  112.        NX_HEIGHT(&r) = rvvsize ;
  113.        NX_X(&r) = 0 ;
  114.        NX_Y(&r) = 0 ;
  115.        NXEraseRect(&r) ;
  116. /*     PSclippath() ;
  117.        PSfill() ; */
  118.        PSsetgray(0.0) ;
  119.        outline() ;
  120.        if (dvifile != NULL)
  121.           dopage() ;
  122.        [cache unlockFocus] ;
  123. #ifdef TRACKCACHE
  124.        { int bsize, bmax, msize ;
  125.          PScachestatus(&bsize, &bmax, &msize) ;
  126.          printf("bsize=%d bmax=%d msize=%d\n", bsize, bmax, msize) ;
  127.        }
  128.        { int used, max, level ;
  129.          PSvmstatus(&level, &used, &max) ;
  130.          printf("vmused=%d\n", used) ;
  131.        }
  132. #endif
  133.     }
  134.     PSflush() ;
  135. /*  [self lockFocus] ; */
  136.     [cache composite:NX_COPY fromRect:rects toPoint:&rects->origin];
  137. /*  [self unlockFocus] ; */
  138.     return self;
  139. }
  140.  
  141. - free
  142. {
  143.    if (cache) [cache free];
  144.    return [super free];
  145. }
  146.  
  147. #define SHOWBUFSIZE (2000)
  148. static char showbuf[SHOWBUFSIZE] ;
  149. static char *showbufp = showbuf ;
  150. static int showx[SHOWBUFSIZE] ;
  151. static int *showxp = showx ;
  152. static int rhh = -3200, rvv = -3200 ;
  153.  
  154. void strflush() {
  155.    if (showx[0] && showbufp > showbuf)
  156.       TPShmove(showx[0]) ;
  157.    if (showbufp > showbuf) {
  158.       if (rhh > -3000) {
  159.          *showxp++ = hh - rhh ;
  160.          rhh = hh ;
  161.       } else
  162.          *showxp++ = 0 ;
  163.       TPSxshow(showbuf, &(showx[1]), showbufp - showbuf) ;
  164. /*    TPSshow(showbuf, showbufp - showbuf) ; */
  165.       showbufp = showbuf ;
  166.       showxp = showx ;
  167.    }
  168. }
  169.  
  170. void texflush() {
  171.    strflush() ;
  172.    rhh = -3200 ;
  173.    rvv = -3200 ;
  174. }
  175.  
  176. void fdrawrule(xx, yy)
  177. halfword xx, yy ;
  178. {
  179.    register shalfword hmin, hmax, vmin, vmax ;
  180.  
  181.    if (xx>0 && yy>0) {
  182.       hmin = hh+hhoffset ;
  183.       hmax = hmin + xx - 1 ;
  184.       vmax = vv+vvoffset ;
  185.       vmin = vmax - yy + 1 ;
  186.       [myView drawRule:xx:yy] ;
  187.    }
  188. }
  189.  
  190. - drawRule:(int)x:(int)y
  191. {
  192.    PSrectfill(hh + hhoffset, vv + vvoffset - y, x, y) ;
  193.    return(self) ;
  194. }
  195. @end
  196.  
  197. void hvpos() {
  198.    texflush() ;
  199.    TPSmoveto(hh + hhoffset, vv + vvoffset) ;
  200.    rhh = hh ;
  201.    rvv = vv ;
  202. }
  203.  
  204. void fdrawchar(c, e)
  205. char c ;
  206. int e ;
  207. {
  208.    if (rvv == vv) {
  209. /*    if (rhh != hh) {
  210.          if (showbufp > showbuf) {
  211.             TPSQshow(showbuf, showbufp-showbuf, hh-rhh) ;
  212.             showbufp = showbuf ;
  213.          } else
  214.             TPSmoveto(hh + hhoffset, vv + vvoffset) ;
  215.          rhh = hh ;
  216.       } */
  217.       if (rhh < -3000)
  218.          hvpos() ;
  219.    } else {
  220.       strflush() ;
  221.       TPSmoveto(hh + hhoffset, vv + vvoffset) ;
  222.       rhh = hh ;
  223.       rvv = vv ;
  224.    }
  225.    *showbufp++ = c ;
  226.    *showxp++ = hh - rhh ;
  227.    rhh = hh ;
  228. }
  229. /*
  230.  *   Set things up for a new page, including calculating the number of
  231.  *   raster rows we have in the buffer.  Everything must be 16-bit
  232.  *   aligned.
  233.  */
  234. id fpageinit() {
  235.    if (landscape && !orientationset)
  236.       tolandscape() ;
  237.    return makenewdoc(rhhsize, rvvsize) ;
  238. }
  239.  
  240. void outline() {
  241.    int safehh, safevv ;
  242.  
  243.    pagereport(pagenum, seq) ;
  244.    safehh = hh ; safevv = vv ;
  245.    hh = - hhmarg - 2 ; vv = - vvmarg - 1 ;
  246.    fdrawrule(hhsize + 4, 2) ;
  247.    vv = vvsize - vvmarg ;
  248.    fdrawrule(2, vvsize + 2) ;
  249.    fdrawrule(hhsize + 4, 2) ;
  250.    hh = hhsize - hhmarg ;
  251.    fdrawrule(2, vvsize + 2) ;
  252.    if (dualpage) {
  253.       hh = hhsize / 2 - hhmarg - 1 ;
  254.       fdrawrule(2, vvsize + 2) ;
  255.    }
  256.    hh = safehh ;
  257.    vv = safevv ;
  258.    orientationset = 1 ;
  259. }
  260.