home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_PICT / Source / CommentedPSCode / RCS / Common,v < prev    next >
Encoding:
Text File  |  1995-06-12  |  24.3 KB  |  1,080 lines

  1. head     1.8;
  2. branch   ;
  3. access   ;
  4. symbols  beta10:1.7;
  5. locks    death:1.8;
  6. comment  @# @;
  7.  
  8.  
  9. 1.8
  10. date     93.04.04.23.30.41;  author death;  state Exp;
  11. branches ;
  12. next     1.7;
  13.  
  14. 1.7
  15. date     93.01.09.21.07.28;  author death;  state Exp;
  16. branches ;
  17. next     1.6;
  18.  
  19. 1.6
  20. date     93.01.01.11.51.35;  author death;  state Exp;
  21. branches ;
  22. next     1.5;
  23.  
  24. 1.5
  25. date     92.12.31.15.34.16;  author death;  state Exp;
  26. branches ;
  27. next     1.4;
  28.  
  29. 1.4
  30. date     92.12.05.23.07.27;  author death;  state Exp;
  31. branches ;
  32. next     1.3;
  33.  
  34. 1.3
  35. date     92.12.03.18.02.00;  author death;  state Exp;
  36. branches ;
  37. next     1.2;
  38.  
  39. 1.2
  40. date     92.11.27.19.38.04;  author death;  state Exp;
  41. branches ;
  42. next     1.1;
  43.  
  44. 1.1
  45. date     92.11.08.09.28.57;  author death;  state Exp;
  46. branches ;
  47. next     ;
  48.  
  49.  
  50. desc
  51. @@
  52.  
  53.  
  54. 1.8
  55. log
  56. @Sun Apr  4 23:30:41 PDT 1993
  57. @
  58. text
  59. @%BEGIN Common
  60. %
  61. %    Pen size 
  62. %
  63. /penWidth 1 def
  64. /penHeight 1 def
  65.  
  66. %
  67. %    The coordinates of the last rectangle used
  68. %
  69. /lastTop 0 def
  70. /lastLeft 0 def
  71. /lastBottom 0 def
  72. /lastRight 0 def
  73. %
  74. %    Define color values
  75. %
  76. /foregroundColor [0 0 0] def
  77. /backgroundColor [1 1 1] def
  78. %
  79. %    Define the three patterns used
  80. %
  81. /backPattern 20 dict def
  82. backPattern begin
  83.     /QDPatType 0 def
  84.     /QDPatData <FFFFFFFFFFFFFFFF>  def    % white
  85.     /QDPatGrey    1 def
  86. end
  87. /penPattern 20 dict def
  88. penPattern begin
  89.     /QDPatType 0 def
  90.     /QDPatData <0000000000000000>  def
  91.     /QDPatGrey    0 def
  92. end
  93. /fillPattern 20 dict def
  94. fillPattern begin
  95.     /QDPatType 0 def
  96.     /QDPatData <0000000000000000>  def    % black
  97.     /QDPatGrey    1 def
  98. end
  99. %
  100. %    set the drawing mode
  101. %
  102. /patternMode    /patCopy    def
  103. %
  104. %    Calculate the PostScript level currently in use.
  105. %
  106. /PSlevel
  107.     systemdict /languagelevel known
  108.         {languagelevel}
  109.         {1}
  110.     ifelse
  111. def
  112.  
  113.  
  114.  
  115. %%%%%%%%%%%%%
  116. %    Name:    usePattern
  117. %    Syntax:    pattern    usePattern    -
  118. %    About:    Set the current drawing patten to the one passed.
  119. %            Note: We do some weird double-use of dictionary in PS 2 code
  120. %%%%%%%%%%%%%
  121. /usePattern
  122. {
  123.     /QDPatternDict exch def
  124.     /patternType QDPatternDict /QDPatType get def
  125.  
  126.     patternType 2 eq
  127.     { QDPatternDict /QDColorValue  get  useColor }
  128.     {
  129.         PSlevel 1 eq
  130.         {
  131.             %
  132.             %    Can't do true patterns, so compute percent gray, and weight by
  133.             %    appropriate ammounts of fore and back colors.
  134.             %
  135.             /patGrey  QDPatternDict /QDPatGrey get  def
  136.             /invGrey 1 patGrey sub def
  137.             0 1 2
  138.             {
  139.                 /index exch def
  140.                 foregroundColor index get invGrey mul
  141.                     backgroundColor index get patGrey mul add
  142.             }
  143.             for
  144.             setrgbcolor
  145.         }
  146.         {
  147.             % PS level 2
  148.             patternType 0 eq
  149.             {
  150.                 /PSPatDict 15 dict def
  151.                 PSPatDict begin
  152.                     /PaintType    1    def
  153.                     /PatternType    1    def
  154.                     /TilingType    1    def
  155.                     /BBox        [0 0 8 8]    def
  156.                     /XStep        8    def
  157.                     /YStep        8    def
  158.                     /myData    QDPatternDict /QDPatData get def
  159.                     /PaintProc    {
  160.                                 %
  161.                                 %    Draw foreground bits, and then draw background
  162.                                 %    bits, using different colors depending on mode.
  163.                                 %
  164.                                 begin
  165.                                     patternMode /patBic eq
  166.                                     patternMode /notPatCopy eq
  167.                                     or
  168.                                         { 0 1 2 { backgroundColor exch get } for }
  169.                                         %patOr, patCopy, and default
  170.                                         { 0 1 2 { foregroundColor exch get } for }
  171.                                     ifelse
  172.                                     setrgbcolor
  173.                                     8 8 false
  174.                                     [1 0 0  1 0 0] 
  175.                                     myData
  176.                                     imagemask
  177.  
  178.                                     patternMode /notPatOr eq
  179.                                     patternMode /notPatCopy eq
  180.                                     or
  181.                                         { 0 1 2 { foregroundColor exch get } for }
  182.                                         % patCopy, notBic and default
  183.                                         { 0 1 2 { backgroundColor exch get } for }
  184.                                     ifelse
  185.                                     setrgbcolor
  186.                                     8 8 true
  187.                                     [1 0 0  1 0 0] 
  188.                                     myData
  189.                                     imagemask
  190.                                 end
  191.                                 } def 
  192.                 end
  193.                 PSPatDict matrix makepattern setpattern
  194.             }
  195.             {
  196.                 % Pat type 2
  197.                 /PSPatDict 20 dict def
  198.                 PSPatDict begin
  199.                     /PaintType    1    def
  200.                     /PatternType    1    def
  201.                     /TilingType    1    def
  202.                     /BBox        [0 0 QDPatternDict  /QDDestWidth  get
  203.                                     QDPatternDict  /QDDestHeight get] def
  204.                     /XStep        QDPatternDict  /QDDestWidth  get def
  205.                     /YStep        QDPatternDict  /QDDestHeight get def
  206.  
  207.                     /ImageType    1    def
  208.                     /Width        QDPatternDict  /Width get def
  209.                     /Height        QDPatternDict  /Height get def
  210.                     /BitsPerComponent
  211.                                 QDPatternDict  /BitsPerComponent get  def
  212.                     /Decode            [ 0 2 BitsPerComponent exp 1 sub ] def
  213.                     /ImageMatrix    [1 0 0  1 0  0]  def
  214.                     /DataSource     QDPatternDict  /QDPatBitmap get def
  215.                     /PaintProc    {
  216.                                     /ourDict exch def 
  217.                                     [/Indexed /DeviceRGB
  218.                                         QDPatternDict  /QDNumColors get
  219.                                         QDPatternDict  /QDColorTable get]
  220.                                     setcolorspace
  221.                                     ourDict  image
  222.                                 } def 
  223.                 end
  224.                 PSPatDict matrix makepattern setpattern
  225.             }
  226.             ifelse
  227.         }
  228.         ifelse
  229.     }
  230.     ifelse
  231. }
  232. def
  233.  
  234.  
  235.  
  236. %%%%%%%%%%%%%
  237. %    Name:    useColor
  238. %    Syntax:    [red green blue] useColor -
  239. %    About:    Given array with R G B values, set the current color to it.
  240. %%%%%%%%%%%%%
  241. /useColor
  242. {
  243.     /colorArray exch def
  244.     colorArray 0 get
  245.     colorArray 1 get
  246.     colorArray 2 get
  247.     setrgbcolor
  248. }
  249. def
  250.  
  251. %%%%%%%%%%%%%
  252. %    Name:    setupForArcPath
  253. %    Syntax:    width height bottom left setupForArcPath  xcoord ycoord radius
  254. %    About:    Given bounds of an oval defined by a rectangle, return its
  255. %            center in undistored space & it's radius (good for use with arc)
  256. %            Also, distort coord system so oval can be drawn (not as circle).
  257. %            If width is > height (computations merely mirrored if reversed)
  258. %            scale coord system, push x coord center, push y coord center as:
  259. %                (ovalBottom-(ovalHeight/2)) * (ovalWidth/ovalHeight)
  260. %            (Get center then unscale it)
  261. %%%%%%%%%%%%%
  262. /setupForArcPath
  263. {
  264.     /ovalLeft exch def
  265.     /ovalBottom exch  def
  266.     /ovalHeight exch  def
  267.     /ovalWidth exch  def
  268.     
  269.     ovalHeight 0 le
  270.     ovalWidth 0 le
  271.     or
  272.     { 0 0 0 }    % if height or with <= 0, return center 0,0 radius 0
  273.     {
  274.         ovalWidth ovalHeight gt
  275.         {
  276.             1 ovalHeight ovalWidth div scale
  277.             ovalLeft ovalWidth 2 div add    % X coordinate center
  278.             ovalBottom ovalHeight 2 div  sub ovalWidth ovalHeight div mul
  279.             ovalWidth 2 div                    % radius
  280.         }
  281.         {
  282.             ovalWidth ovalHeight div 1 scale
  283.             ovalLeft ovalWidth 2 div  add   ovalHeight ovalWidth div   mul
  284.             ovalBottom ovalHeight 2 div sub    % Y coord center
  285.             ovalHeight 2 div                % radius
  286.         }
  287.         ifelse
  288.     }
  289.     ifelse
  290. }
  291. def
  292.  
  293. %%%%%%%%%%%%%
  294. %    Name:    regionBounds
  295. %    Syntax:    top left bottom right regionBounds -
  296. %    About:    Build a closed path given the coordinates on the stack.
  297. %%%%%%%%%%%%%
  298. /regionBounds
  299. {
  300.     /right    exch def
  301.     /bottom    exch def
  302.     /left        exch def
  303.     /top        exch def
  304.  
  305.     newpath
  306.         left top moveto
  307.         right top lineto
  308.         right bottom lineto
  309.         left bottom lineto
  310.     closepath
  311. }
  312. def
  313.  
  314. %%%%%%%%%%%%%
  315. %    Name:    regionPath
  316. %    Syntax:    x y ... x y  n  regionPath -
  317. %    About:    Given N, and N pairs of x,y coords which define a region's edge,
  318. %            build a path through these coordinates.
  319. %%%%%%%%%%%%%
  320. /regionPath
  321. {
  322.     /numShapes exch def
  323.     newpath
  324.     numShapes
  325.     {
  326.         /numPoints exch def
  327.         /y exch def
  328.         /x exch def
  329.         x y moveto
  330.         numPoints 1 sub
  331.         {
  332.             /y exch def
  333.             /x exch def
  334.             x y lineto
  335.         }
  336.         repeat
  337.         closepath
  338.     }
  339.     repeat
  340. }
  341. def
  342.  
  343. %%%%%%%%%%%%%
  344. %    Name:    startPict
  345. %    Syntax:    num startPict -
  346. %    About:    Called before any converted pict data.  Do any setup here.
  347. %%%%%%%%%%%%%
  348. /startPict
  349.     {pop}
  350. def
  351.  
  352. %%%%%%%%%%%%%
  353. %    Name:    QDClip    [0001]
  354. %    Syntax:    regionInfo QDclip -
  355. %    About:    Sets the clipping path for the drawing. If shapes in region
  356. %            other than bounding rect, build their path and clip to them too.
  357. %%%%%%%%%%%%%
  358. /QDclip
  359. {
  360.     initclip
  361.     regionBounds
  362.     clip
  363.     /numShapes exch def
  364.     numShapes  0 gt
  365.     {
  366.         numShapes
  367.         regionPath
  368.         clip
  369.     }
  370.     if
  371. }
  372. def
  373.  
  374. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  375. %    Name:    endPict    [00FF]
  376. %    Syntax:    - endPict -
  377. %    About:    Marks the end of a picture.  Do any cleanup here.
  378. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  379. /endPict
  380.     {}
  381. def
  382.  
  383. %%%%%%%%%%%%%
  384. %    Name:    headerOp    [0C00]
  385. %    Syntax:    num num num num num num headerOp -
  386. %    About:    This appears to do nothing for PICT 1 or 2, so we ignore it.
  387. %%%%%%%%%%%%%
  388. /headerOp
  389.     {pop pop pop pop pop pop}
  390. def
  391.  
  392.  
  393. %END Common
  394.  
  395. @
  396.  
  397.  
  398. 1.7
  399. log
  400. @Sat Jan  9 21:07:28 PST 1993
  401. @
  402. text
  403. @d38 1
  404. a38 1
  405.     /QDPatData <FFFFFFFFFFFFFFFF>  def    % white
  406. @
  407.  
  408.  
  409. 1.6
  410. log
  411. @Fri Jan  1 11:51:35 PST 1993
  412. @
  413. text
  414. @d3 1
  415. a3 1
  416. %    Define the default pen size 
  417. d9 1
  418. a9 1
  419. %    Store the last rectangle coordinates that were used by the various routines
  420. a14 1
  421.  
  422. d16 1
  423. a16 1
  424. %    Define color values (black foreground, white background)
  425. a19 1
  426.  
  427. d21 1
  428. a21 4
  429. %    Define the patterns tha will be used
  430. %        The background pattern
  431. %        The pen pattern
  432. %        The fill pattern
  433. d32 1
  434. a32 1
  435.     /QDPatData <0000000000000000>  def    % black
  436. a40 1
  437.  
  438. d42 1
  439. a42 1
  440. %    Mode
  441. d45 3
  442. a47 12
  443.  
  444. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  445. %    Utility value:     PSlevel
  446. %    Syntax:            - PSlevel num
  447. %    Description:
  448. %        This will return the current PS language level as an integer.
  449. %        Because the languagelevel operator is undefined for level 1
  450. %        PS, this checks whether the operator is known currently.
  451. %        If so, it returns the number it returns.  If it isn't known, we
  452. %        return 1.
  453. %    Bugs:
  454. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  455. d57 6
  456. a62 10
  457. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  458. %    Utility routine:     usePattern
  459. %    Syntax:            pattern    usePattern    -
  460. %    Description:
  461. %        This changes the current drawing 'pattern'.
  462. %        While QuickDraw has 3 patterns in use at once, we keep only one here,
  463. %        switching between them as needed.
  464. %    Notes:
  465. %        PATTERN DATA HAS BEEN INVERTED FOR B&W!!  REVERSE MODES!
  466. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  467. d67 1
  468. d69 1
  469. a70 7
  470.         /colorpat QDPatternDict /QDColorValue  get def
  471.         0 1 2
  472.             {colorpat exch get}
  473.         for
  474.         setrgbcolor
  475.     }
  476.     {
  477. d74 2
  478. a75 3
  479.             %    No way to do true patterns, so compute an approximate RGB value
  480.             %    that vaguely represents the pattern.  Get the % grey of the B&W pattern
  481.             %    and then use appropriate percentages of fore and background color.
  482. a78 1
  483.             /patGrey 0 invGrey sub 1 add def
  484. d83 1
  485. a83 1
  486.                     backgroundColor index get patGrey mul add 2 div
  487. d89 1
  488. a89 1
  489.             % Ps level 2
  490. d92 1
  491. a92 1
  492.                 /PSPatDict 10 dict def
  493. d102 17
  494. a118 21
  495.                                     begin
  496.                                         patternMode /patBic eq
  497.                                         patternMode /notPatCopy eq
  498.                                         or
  499.                                         {
  500.                                             backgroundColor 0 get
  501.                                             backgroundColor 1 get
  502.                                             backgroundColor 2 get
  503.                                         }
  504.                                         {
  505.                                             %patOr, patCopy, and default
  506.                                             foregroundColor 0 get
  507.                                             foregroundColor 1 get
  508.                                             foregroundColor 2 get
  509.                                         }
  510.                                         ifelse
  511.                                         setrgbcolor
  512.                                         8 8 true
  513.                                         [1 0 0  1 0 0] 
  514.                                         myData
  515.                                         imagemask
  516. d120 13
  517. a132 21
  518.                                         patternMode /notPatOr eq
  519.                                         patternMode /notPatCopy eq
  520.                                         or
  521.                                         {
  522.                                             foregroundColor 0 get
  523.                                             foregroundColor 1 get
  524.                                             foregroundColor 2 get
  525.                                         }
  526.                                         {
  527.                                             % patCopy, notBic and default
  528.                                             backgroundColor 0 get
  529.                                             backgroundColor 1 get
  530.                                             backgroundColor 2 get
  531.                                         }
  532.                                         ifelse
  533.                                         setrgbcolor
  534.                                         8 8 false
  535.                                         [1 0 0  1 0 0] 
  536.                                         myData
  537.                                         imagemask
  538.                                     end
  539. d138 1
  540. d144 2
  541. a145 1
  542.                     /BBox        [0 0 QDPatternDict  /QDDestWidth  get QDPatternDict  /QDDestHeight get] def
  543. d152 3
  544. a154 2
  545.                     /BitsPerComponent    QDPatternDict  /BitsPerComponent get  def
  546.                     /Decode        [ 0 2 BitsPerComponent exp 1 sub ] def
  547. d161 2
  548. a162 1
  549.                                         QDPatternDict  /QDColorTable get] setcolorspace
  550. d176 7
  551. a182 14
  552. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  553. %    Utility routine:     useColor
  554. %    Syntax:            [red green blue] useColor -
  555. %    Description:
  556. %        This is called with a three element array on the stack,
  557. %        where the elements of that array represent an RGB color
  558. %        value that was specified, perhaps, with the pict foreground or
  559. %        background operators.   We take this array, extract its contents
  560. %        and set the current pen color to this rgb value.  note that we
  561. %        use setrgbcolor, since this is Level 1 compatible, and so we don't
  562. %        need to worry about the level of PS here.
  563. %    Bugs:
  564. %        Like many other things here, this does no argument checking.
  565. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  566. d193 2
  567. a194 123
  568.  
  569. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  570. %    Utility routine:     PICTline
  571. %    Syntax:            num num num num PICTline -
  572. %    Description:
  573. %        This draws a line from the start x and y coordinates, to
  574. %        the destination x and y coordinates.  It uses the current
  575. %        pen pattern and pen width and height to do this.
  576. %        Note taht it special cases the instance when the penheight and width
  577. %        are both 1, and just draws a simple line in PS (this provides more
  578. %        accurate results).  Otherwise, it draws a line that is like one
  579. %        in a PICT file, which can have different heights and widths, and
  580. %        so on.  See inside mac V. 1
  581. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  582. /PICTline
  583. {
  584.     /endY exch def
  585.     /endX exch def
  586.     /startY exch def
  587.     /startX exch def
  588.  
  589.     %
  590.     %    If the pen width or height is ever 0 or less, we don't draw anything.
  591.     %    This is following the lead of MacDraw I and II (of course, those don't even display
  592.     %    pens with non equal width ends.  So, maybe this is a wrong assumption to be
  593.     %    making here
  594.     %
  595.     penHeight 0 gt
  596.     penWidth 0 gt
  597.     and
  598.     {
  599.         gsave
  600.             penPattern usePattern
  601.             newpath
  602.                 %
  603.                 %    If the pen size is 1 on each side, do a normal lineto.
  604.                 %
  605.                 penHeight 1 eq
  606.                 penWidth 1 eq
  607.                 and
  608.                 {
  609.                     startX startY moveto
  610.                     endX endY lineto
  611.                     stroke
  612.                 }
  613.                 {
  614.                     %
  615.                     %    Draw a thicker line.  Figure out where to draw from and
  616.                     %    to (there are 6 vertices on the line that gets drawn), depending
  617.                     %    on how the start and end coordiantes relate.
  618.                     %
  619.                     endY startY lt
  620.                     {
  621.                         endX startX gt
  622.                         {
  623.                             startX startY moveto
  624.                             endX endY lineto
  625.                             endX penWidth add  endY lineto
  626.                             endX penWidth add  endY penHeight add lineto
  627.                             startX penWidth add  startY penHeight add lineto
  628.                             startX  startY penHeight add lineto
  629.                         }
  630.                         {
  631.                             startX penWidth add startY moveto
  632.                             endX penWidth add endY lineto
  633.                             endX endY lineto
  634.                             endX endY penHeight add lineto
  635.                             startX startY penHeight add lineto
  636.                             startX penWidth add startY penHeight add lineto
  637.                         }
  638.                         ifelse
  639.                     }
  640.                     {
  641.                         endX startX gt
  642.                         {
  643.                             startX startY moveto
  644.                             startX penWidth add startY lineto
  645.                             endX penWidth add endY lineto
  646.                             endX penWidth add endY penHeight add lineto
  647.                             endX endY penHeight add lineto
  648.                             startX startY penHeight add lineto
  649.                         }
  650.                         {
  651.                             startX startY moveto
  652.                             endX endY lineto
  653.                             endX endY penHeight add lineto
  654.                             endX penWidth add endY penHeight add lineto
  655.                             startX penWidth add  startY penHeight add lineto
  656.                             startX penWidth add  startY lineto
  657.                         }
  658.                         ifelse
  659.                     }
  660.                     ifelse
  661.                 closepath
  662.                 fill
  663.             }    % end of whether we have sides of length 1 or greater.
  664.             ifelse
  665.         grestore
  666.     }    % End of test for >0 length sides
  667.     if
  668. } def
  669.  
  670.  
  671.  
  672. %    About:    Use coords of a rectangle, plus the starting and finishing
  673. %        angle, and frames the outline of a portion of an oval's outline
  674. %        (an arc), using the values of penWidth and penHeight.
  675. %        This is accomplished in one of 2 cases:
  676. %        1) The penwidth and height are both 1,
  677. %        2) The width of the oval (that the arc is a part of) is greater
  678. %            than its height.
  679. %        3) The Oval's height is greater than its width.
  680. %        The first is special cased because it looks slightly better this
  681. %        way, and will doubtlessly be the most common case.  In 2 & 3, user
  682. %        space is necessarily distorted so we can achieve oval shapes.
  683. %        Note: to get the penwidth and heigh effect, we frame an oval inside
  684. %        an oval, and then fill the space between them.
  685. %        Note that the last* values are modified and used here
  686.  
  687.  
  688.  
  689. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  690. %    utility:    setupForArcPath
  691. d196 8
  692. a203 25
  693. %    Description:
  694. %        Given the width and height of an oval, plus the coords of it's bottom and left,
  695. %        this computes the oval's center in non-distorted user space, and the proper
  696. %        'radius' to use to draw the oval.  It also scales user space appropriately.
  697. %        With all this messy math done, it returns the x and y coord of the center, plus
  698. %        the radius value on the stack to the caller.
  699. %        The intention is that the user call this with the width, etc, of the oval, and
  700. %        get back numbers ready to be plugged into arc or arcn or whatever.
  701. %        The code is a little dense on math.  But, the basic ideas are 'simple'.
  702. %        First, we scale user space appropriatley.  Then, we compute the xcoord, then
  703. %        the ycoord and finally the radius (pushing all on the stack as we go).
  704. %        If our width is larger than our height, we compute these one way, otherwise
  705. %        we compute them another.  The raidus is always half the length of the longer.
  706. %        Ine each scenario, one of the coords is simply half way along the width or
  707. %        height in an obvious way.  In the case of getting the Y coordinate when the
  708. %        width is greater, we compute: 
  709. %            ((ovalHeight/2)+ovalBottom) * (ovalWidth/ovalHeight)
  710. %        That is, gets center, then unscales it so it will be in the right position in
  711. %        the unscaled userspace.  Similar computation in the other case.
  712. %    Bugs:
  713. %        This header comment is much longer than the code itself...  =)
  714. %        Remove the trapping for oval sizes that are too big, and you can get
  715. %        some  cute results! =)
  716. %    removed a 1 add from the bottom height and width
  717. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  718. d211 2
  719. a212 2
  720.     0 ovalHeight eq    % don't try to draw if our width or height is 0
  721.     0 ovalWidth eq
  722. d214 1
  723. a214 1
  724.     { 0 0 0 }    % return a center of 0,0 with a radius of 0
  725. d220 2
  726. a221 2
  727.             ovalBottom ovalHeight 2 div  sub ovalWidth ovalHeight div mul    % Y coord center
  728.             ovalWidth 2 div                % radius
  729. d225 2
  730. a226 2
  731.             ovalLeft ovalWidth 2 div  add   ovalHeight ovalWidth div   mul  % X coordinate center
  732.             ovalBottom ovalHeight 2 div sub% Y coord center
  733. d235 2
  734. a236 4
  735.  
  736.  
  737. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  738. %    utility:    regionBounds
  739. d238 2
  740. a239 11
  741. %    Description:
  742. %        The top four coordinates on the stck when a region opcode is encountered
  743. %        is the top left borrom and right coordinates of the rectangle that bounds/clips
  744. %        the whole of the region shape.  This returns the path formed by this rectangle
  745. %        to the caller.
  746. %    Notes:
  747. %        Ideally, this would be integrated with whatever routine creates the path
  748. %        for the rest of the region.  This might, however, require that two paths
  749. %        be returned to the user.  As this is difficult, I have opted to deal with doing
  750. %        the processing of region data in two passes.
  751. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  752. d246 1
  753. a246 3
  754.     %
  755.     % Build a rectangular path...
  756.     %
  757. d249 3
  758. a251 3
  759.         right 1 add top lineto
  760.         right 1 add bottom 1 add lineto
  761.         left bottom 1 add lineto
  762. d256 6
  763. a261 16
  764.  
  765. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  766. %    utility:    regionPath
  767. %    Syntax:    [x y x] ... [x y x] n  top left bottom right regionPath -
  768. %    Description:
  769. %        Takes a region from the stack, and theoretically builds a path from it.
  770. %        Realistically we mostly just discard it, because building a region, in general, is going
  771. %        to be more work than it seems to warrant. 
  772. %        So, instead, we discard the many region lines, if they exist, and build a simple
  773. %        path around the bounding rect of the region.
  774. %        Data on the stack consists of: a bounding rectangle, a number of region segments
  775. %        and then that number of region segment.  Each segment is a 3 element array:
  776. %        [x1 y1, x2] which defines a line with y coordinates y1 and x ones from x1 to x2.
  777. %        (that is, it describes the line from x1,y1 to x2,y1
  778. %    Notes:
  779. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  780. d285 2
  781. a286 2
  782. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  783. %    uniltiy routine: startPict
  784. d288 2
  785. a289 7
  786. %    Description:
  787. %        This routine balances the endPict routine that is called at the end of
  788. %        the data that came from a pict file.  It kinda corresponds to
  789. %        the ininitial version opcode in the pict file, in that it is passed the
  790. %        version number of the source pict file.  Mainly, though, it allows
  791. %        one to do any setup one needs to do before starting displyaing the pict.
  792. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  793. d294 6
  794. a299 13
  795.  
  796. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  797. %    Opcode:    0001
  798. %    Name:    QDClip
  799. %    Syntax:    macRegion QDclip -
  800. %    Description:
  801. %        Sets the PS clipping path to the path described by the mac region
  802. %        Note that we check the number of shapes following the main bounding
  803. %        box for the region.  If it is 0, then we do nothing.  Otherwise, we build a path
  804. %        representing them, and intersect it with the current clip path.  Doing
  805. %        this prevents us from calling regionPath then clip with no shapes, whichs
  806. %        causes an empty clip path (nothing gets drawn)
  807. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  808. d313 2
  809. a314 1
  810. } def
  811. a315 1
  812.  
  813. d317 1
  814. a317 2
  815. %    Opcode:    00FF
  816. %    Name:    endPict
  817. d319 1
  818. a319 3
  819. %    Description:
  820. %        This should mark the end of the picture.  So.  If any cleaning
  821. %        needs to be done, it should be done here
  822. d325 2
  823. a326 4
  824.  
  825. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  826. %    Opcode:    00C0
  827. %    Name:    headerOp
  828. d328 2
  829. a329 6
  830. %    Description:
  831. %        Another of those fine opcodes that isn't very well defined.
  832. %        It's a pict2 opcode.  It takes -1, followed by 4 32bit numbers, follwoed by -1 (I think)
  833. %        At the moment is appears to do nothing crucial.  So, we ignore it.
  834. %    Bugs:
  835. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  836. @
  837.  
  838.  
  839. 1.5
  840. log
  841. @Thu Dec 31 15:34:16 PST 1992
  842. @
  843. text
  844. @@
  845.  
  846.  
  847. 1.4
  848. log
  849. @Sat Dec  5 23:07:27 PST 1992
  850. @
  851. text
  852. @d28 1
  853. a28 1
  854. /backPattern 10 dict def
  855. d31 1
  856. a31 1
  857.     /QDPatData <FFFFFFFF>  def    % white
  858. d34 1
  859. a34 1
  860. /penPattern 10 dict def
  861. d37 1
  862. a37 1
  863.     /QDPatData <00000000>  def    % black
  864. d40 1
  865. a40 1
  866. /fillPattern 10 dict def
  867. d43 1
  868. a43 1
  869.     /QDPatData <FFFFFFFF>  def    % white
  870. d47 4
  871. d80 1
  872. d86 1
  873. a86 3
  874.     patternType 0 eq
  875.     patternType 1 eq
  876.     or
  877. d88 7
  878. d116 87
  879. a202 1
  880.         
  881. a205 7
  882.     {
  883.         /colorpat QDPatternDict /QDColorValue  get def
  884.         0 1 2
  885.             {colorpat exch get}
  886.         for
  887.         setrgbcolor
  888.     }
  889. a209 1
  890.  
  891. d338 17
  892. d381 1
  893. d386 3
  894. a388 3
  895.     /ovalBottom exch 1 add def
  896.     /ovalHeight exch 1 add def
  897.     /ovalWidth exch 1 add def
  898. d498 2
  899. a499 3
  900. {
  901.     pop
  902. } def
  903. d542 14
  904. @
  905.  
  906.  
  907. 1.3
  908. log
  909. @Thu Dec  3 18:01:59 PST 1992
  910. @
  911. text
  912. @d1 1
  913. d22 24
  914. d47 1
  915. d49 1
  916. a49 1
  917. %    Utility routine:     PSlevel
  918. a59 1
  919. {
  920. d64 54
  921. d439 1
  922. a439 35
  923.  
  924.  
  925.  
  926.  
  927. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  928.  
  929. %
  930. %    Define the patterns tha will be used (in this context, 1 is black, 0 is white)
  931. %        The background pattern
  932. %        The pen pattern
  933. %        The fill pattern
  934. %
  935. /backPattern 0 def
  936. /penPattern 1 def
  937. /fillPattern 0  def
  938.  
  939.  
  940.  
  941.  
  942. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  943. %    Utility routine:     usePattern
  944. %    Syntax:            pattern    usePattern    -
  945. %    Description:
  946. %        This changes the current drawing 'pattern'.
  947. %        While QuickDraw has 3 patterns in use at once, we keep only one here,
  948. %        switching between them as needed.
  949. %    Notes:
  950. %        At the moment, a 'pattern' is simply represented as a shade of grey, so,
  951. %        we just change the grey level when called
  952. %    @@@@ PS 2
  953. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  954. /usePattern
  955.     { 0 exch sub 1 add setgray }
  956. def
  957.  
  958. @
  959.  
  960.  
  961. 1.2
  962. log
  963. @Fri Nov 27 19:38:03 PST 1992
  964. @
  965. text
  966. @d28 3
  967. a30 3
  968. %        PS, this briefly patches the error dictionary so that if we try to
  969. %        call languagelevel in a level 1 environment, we will recover
  970. %        effortlessly, and return the proper number anyway (1).
  971. d35 4
  972. a38 8
  973.     errordict begin
  974.     /oldundef {undefined} def
  975.     /undefined {pop 1} def
  976.  
  977.     languagelevel
  978.  
  979.     /undefined {oldundef} def
  980.     end
  981. d256 3
  982. a258 3
  983.         right top lineto
  984.         right bottom lineto
  985.         left bottom lineto
  986. d289 1
  987. a289 1
  988.         numPoints 2 mul 1 sub
  989. a314 4
  990.     %
  991.     %    Invert the coord system to match PICT view of the world.
  992.     %
  993.     [1 0 0 -1 0 255] concat
  994. d317 1
  995. d324 5
  996. d335 8
  997. a342 3
  998. %%% if there are no shapes, when what happens with this?
  999.     regionPath
  1000. %%%%%%%%%%%%%%%%%%%%%%    clip
  1001. @
  1002.  
  1003.  
  1004. 1.1
  1005. log
  1006. @Sun Nov  8 09:28:57 PST 1992
  1007. @
  1008. text
  1009. @d15 5
  1010. d21 1
  1011. d23 50
  1012. d236 33
  1013. a281 6
  1014. %        If we ever process this stuff for real, we should store values as a 'last region'
  1015. %        for reuse later (?).
  1016. %        It would probably be nicer, actually, to do the region-data processing in the
  1017. %        converter program, and not here.  So, if this is ever enabled, this routine will
  1018. %        probably need significant changes (but, the final code will probably be pretty
  1019. %        simple... basically  this could be described as just a polygon).
  1020. d285 1
  1021. a285 14
  1022.     /right    exch def
  1023.     /bottom    exch def
  1024.     /left    exch def
  1025.     /top    exch def
  1026.     /segments exch def
  1027.     %
  1028.     %    read in the segments making up the region.
  1029.     %
  1030.     segments
  1031.         { pop }
  1032.     repeat    % for the number of segments
  1033.     %
  1034.     % Build a rectangular path...
  1035.     %
  1036. d287 16
  1037. a302 5
  1038.         left top moveto
  1039.         right top lineto
  1040.         right bottom lineto
  1041.         left bottom lineto
  1042.     closepath
  1043. d306 18
  1044. d327 1
  1045. a327 1
  1046. %    Name:    endPict
  1047. d335 3
  1048. d339 1
  1049. a339 1
  1050.     clip
  1051. a363 8
  1052. %    Define our B&W patterns
  1053. %
  1054. /penPattern 0 def
  1055. /fillPattern 0 def
  1056. /backPattern 0 def
  1057.  
  1058.  
  1059. %
  1060. a373 18
  1061. %
  1062. %    Define color values
  1063. %
  1064. /fgColor 0 def
  1065. /bkColor 1 def
  1066.  
  1067. %
  1068. %    These are constants used to set the fgColor and bkColor, above.  They should have
  1069. %    real values to match their names, rather than B&W colors...
  1070. %
  1071. /blackColor 1 def
  1072. /whiteColor 1 def
  1073. /redColor 1 def
  1074. /greenColor 1 def
  1075. /blueColor 1 def
  1076. /cyanColor 1 def
  1077. /magentaColor 1 def
  1078. /yellowColor 1 def
  1079. @
  1080.