home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3.4.17 [SPARC, PA-RISC] / nextstep33_risc.iso / NextLibrary / TeX / tex / src / texview / pots.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-07  |  4.3 KB  |  186 lines

  1. /*
  2.  *   We need some routines to update pot values and hoffset/voffset pairs.
  3.  */
  4. #include "structures.h"
  5. /*
  6.  *   These are all the externals we use.
  7.  */
  8. extern real conv, pxlconv ;
  9. extern real possibmag[] ;
  10. extern integer iconv ;
  11. extern real vconv ;
  12. extern integer viconv ;
  13. extern real screendpi ;
  14. extern shalfword hhoffset, vvoffset ;
  15. extern shalfword colsize ;
  16. extern real hsize, vsize, hmarg, vmarg ;
  17. extern real defhsize, defvsize, defhmarg, defvmarg ;
  18. extern shalfword hhsize, vvsize, hhmarg, vvmarg ;
  19. extern shalfword rhhsize, rvvsize, rhhmarg, rvvmarg ;
  20. extern shalfword vscreen ;
  21. extern shalfword hwindow, vwindow, hwindowwidth, vwindowwidth ;
  22. extern shalfword vvmax, hhmax ;
  23. extern shalfword vvmin, hhmin ;
  24. extern FILE *dvifile ;
  25. extern integer dvimag, num, den ;
  26. extern shalfword vscreenheight ;
  27. extern shalfword vwindowheight ;
  28. extern Boolean dualpage, pagedrawn ;
  29. extern void reportnewdpi() ;
  30. extern void TPSdefres() ;
  31. extern int actualdpi ;
  32. extern int *existsize, existsize100[], existsize300[], existsize400[] ;
  33. /*
  34.  *   functions we use
  35.  */
  36. extern void recalculate(), recalc(), fontinit() ;
  37. extern void makenewdoc() ;
  38. extern void notifysizes() ;
  39. /*
  40.  *   A Boolean to indicate that the user set the sizes, so we shouldn't
  41.  *   muck with them.
  42.  */
  43. Boolean usersetsizes ;
  44. Boolean landscape ;
  45. Boolean landset ;
  46. /*
  47.  *   Some variables setting the dimensions we work in.
  48.  *
  49.  *      inches, cm, picas, points
  50.  */
  51. int dimstyle ;
  52. real intostyle[4] = { 1.0, 2.54, 6.0225, 72.27 } ;
  53. real intos ;
  54. /*
  55.  *   Here we set the sizes back to their default sizes.
  56.  */
  57. void resetsizes() {
  58.    landscape = 0 ;
  59.    landset = 0 ;
  60.    usersetsizes = 0 ;
  61.    hsize = defhsize ;
  62.    vsize = defvsize ;
  63.    hmarg = defhmarg ;
  64.    vmarg = defvmarg ;
  65.    if (dualpage)
  66.       hsize += hsize ;
  67.    recalculate() ;
  68. }
  69. /*
  70.  *   If we get a landscape special, we call this to reset things.
  71.  */
  72. void tolandscape() {
  73.    register real t ;
  74.  
  75.    if (! landset) {
  76.       landset = 1 ;
  77.       usersetsizes = 0 ;
  78.       if (dualpage) {
  79.          t = hsize ;
  80.          hsize = vsize * 2.0 ;
  81.          vsize = hsize / 2.0 ;
  82.       } else {
  83.          t = hsize ;
  84.          hsize = vsize ;
  85.          vsize = t ;
  86.       }
  87.       t = hmarg ;
  88.       hmarg = vmarg ;
  89.       vmarg = t ;
  90.       if (dualpage)
  91.          hsize += hsize ;
  92.       recalculate() ;
  93.    }
  94.    pagedrawn = 0 ;
  95. }
  96.  
  97. void todualornot() {
  98.    if (dualpage)
  99.       hsize += hsize ;
  100.    else
  101.       hsize = hsize / 2.0 ;
  102.    recalculate() ;
  103. }
  104.  
  105. void newpapersize(h, v)
  106. long h, v ;
  107. {
  108.    hsize = h / 4736286.72 ;
  109.    vsize = v / 4736286.72 ;
  110.    if (dualpage) {
  111.       hsize = hsize * 2.0 ;
  112.    }
  113.    hmarg = 1.0 ;
  114.    vmarg = 1.0 ;
  115.    recalculate() ;
  116.    pagedrawn = 0 ;
  117. }
  118. /*
  119.  *   Here we recalculate various things when hsize or most anything else
  120.  *   changes.
  121.  */
  122. void
  123. recalculate() {
  124. #define MARG (8)
  125.    vvsize = vsize * screendpi + 0.5 ;
  126.    vvmarg = vmarg * screendpi + 0.5 ;
  127.    hhsize = hsize * screendpi + 0.5 ;
  128.    hhmarg = hmarg * screendpi + 0.5 ;
  129.    rhhsize = hhsize + 2 * MARG ;
  130.    rvvsize = vvsize + 2 * MARG ;
  131.    rhhmarg = hhmarg + MARG ;
  132.    rvvmarg = vvmarg + MARG ;
  133.    hhoffset = rhhmarg ;
  134.    vvoffset = rvvmarg ;
  135.    hhmin = -MARG ;
  136.    hhmax = hhsize + MARG ;
  137.    vvmin = -MARG ;
  138.    vvmax = vvsize + MARG ;
  139.    notifysizes() ;
  140. }
  141. /*
  142.  *   If the dots per inch change, we call this to redo everything.
  143.  */
  144. void newdpi() {
  145.    if (screendpi == 300.0 || screendpi == 400.0) {
  146.       actualdpi = screendpi ;
  147.       existsize = ((screendpi == 300.0) ? existsize300 : existsize400) ;
  148.    } else {
  149.       actualdpi = 100 ;
  150.       existsize = existsize100 ;
  151.    }
  152.    recalculate() ;
  153.    TPSdefres((double)screendpi) ;
  154.    if (dvifile != NULL) {
  155.       conv = num * screendpi * dvimag / ( den * 254000000.0 ) ;
  156.       pxlconv = dvimag * screendpi / 1000.0 ;
  157.       iconv = 1.0 / conv + 0.5 ;
  158.       vconv = conv ;
  159.       viconv = 1.0 / vconv + 0.5 ;
  160.       fontinit() ;
  161.    }
  162.    pagedrawn = 0 ;
  163.    reportnewdpi() ;
  164. }
  165. /*
  166.  *   Here we calculate the dpi needed to draw the entire page on the
  167.  *   current list.
  168.  */
  169.  
  170. void newfullsize() {
  171.    register int i ;
  172.    register real temp, newdpi ;
  173.  
  174.    temp = ((real)(hwindow - 2 * MARG)) / hsize ;
  175.    newdpi = ((real)(vwindow - 2 * MARG)) / vsize ;
  176.    if (temp < newdpi)
  177.       newdpi = temp ;
  178.    for (i=1; possibmag[i] != 0.0 && possibmag[i] < newdpi; i++) ;
  179.    if (i==1)
  180.       newdpi = possibmag[1] ;
  181.    else
  182.       newdpi = possibmag[i-1] ;
  183.    possibmag[0] = newdpi ;
  184. }
  185. extern char temperrorbuf[] ;
  186.