home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-09-28 | 4.6 KB | 193 lines | [TEXT/MPS ] |
- %
- % File: TransformProcs.ps
- %
- % Contains: This file contains the procedures used for Skia transofrms.
- % These procedures are (so far) Portable PostScript.
- %
- % Version: Technology: Quickdraw GX 1.1.x.
- %
- % Copyright: © 1991-7 by Apple Computer, Inc., all rights reserved.
- %
- %
-
- % File contains the following Procedures:
- % MakeTrDict
- % SetTr
- % MapCTM
- % QD2Clip
-
- %
- % Routine scales 6 mapping values by z.
- % a b c d e f z ScaleMappingValues a/z b/z c/z e/z f/z
- % Note, z is an integer that is really a fract.
- /ScaleMappingValues {
-
- % Convert the fract into a float.
- 1073741824 div % divide by 2^30 since fract is 2.30 bitwise
-
- % divide all 6 numbers by the scale.
- 7 1 roll
- 6 {
- 6 index div
- 6 -1 roll
- } repeat
-
- 7 -1 roll pop % Get rid of z.
-
- } Bdef
-
-
- %
- % Routine takes 7 mapping values and makes a postscript matrix.
- %
- % a b c d e f z MakMatrix matrix
- /MakMatrix {
-
- ScaleMappingValues
- matrix astore
-
- } Bdef
-
-
- %<FF>
- % MapCTM: Procedure maps the CTM by the specified mapping values.
- %
- % a b c d e f MapCTM -
- %
- % a b c d e f z: Values for matrix [a/z b/z c/z d/z e/z f/z]
- /MapCTM {
-
- ScaleMappingValues % Fix the numbers.
- ScratchMatrix astore % Make a matrix from the 6 values.
- concat % Concatonate it with the CTM.
- CurrPat null ne { % If there is a pattern.
- SynchPatMatrix % Synch up the new CTM with the pattern.
- } if
-
- } Bdef
-
-
-
- %<FF>
- %
- % Clipping dictionary.
- %
- /ClipDict 5 dict dup 3 -1 roll Xdef begin % Create a dictionary, name it ClipDict.
-
- % Framed means clip to the stroke-path (should be hairline). Make sure we don't get limitcheck.
- /Fr {
- currentlinewidth % Save the current line width on the stack
- 0 setlinewidth % Make it a hairline for the framed clip
- /strokepath 0 AvoidLimit % Get the filled path of the framed object
- clip % Make it the current clip
- setlinewidth % Restore the linewidth from saved value on the stack.
- } Bdef
-
- % Inverse fill is current path + FullPath and then eoclip. Make sure we don't get limitcheck.
- /In {FullPath /eoclip 0 AvoidLimit} Bdef
-
- % even-odd is eoclip
- /Eo {/eoclip 0 AvoidLimit} Bdef
-
- % Winding number fill is normal PostScript clip
- /W {/clip 0 AvoidLimit} Bdef
-
- % no fill means clip everything out.
- /No {
- newpath % Clear out whatever path was there
- EmptyPath % Put an empty path there.
- clip
-
- } Bdef
-
- end %ClipDict
-
- %
- % QD2Clip Operator. Does all Skia clips. Makes sure we have a new path afterwards.
- %
- % fillKey QD2Clip -
- %
- % fillKey: A valid Skia fill key.
- %
- /QD2Clip {
-
- ClipDict exch get exec % Execute the clip procedure according to the fillKey.
- newpath % We always want a new path afterwards.
-
- } Bdef
-
-
-
-
- %<FF>
- % The MakeTrDict proc:
- %
- % Makes a dictionary out of the parts of a Skia transform.
- %
- % clipGeom clipFill matrix MakeTrDict trDict
- %
- % clipGeom: The procedure describing the clip shape's geometry.
- % clipFill: The fill key for the clip shape.
- % matrix: The matrix to use for this transform
- % dict: The dictionary created by MakeTrDict
- %
- /MakeTrDict {
-
- 7 dict begin % Create a dictionary, Make it current dict, leave on op stack.
-
- /Mapping Xdef
- /ClipFill Xdef
- /ClipGeom Xdef
-
- /xTrans Mapping 4 get def % Get Translation component of Mapping.
- /yTrans Mapping 5 get def
-
- % Define the procedure to set the clip, make it do nothing if clip is full shape.
-
- /ClipGeom load 0 get /FullPath cvx eq ClipFill /Eo eq ClipFill /W eq or and not {
-
- /TrSetClip {ClipGeom ClipFill QD2Clip} BDef
- /isSimpleTranslation false def % Transform not simple if there's a clip.
-
- } {
-
- /TrSetClip {} def
-
- % Check to see if Mapping is a simple translation.
-
- Mapping aload pop pop pop % Stack is: a b c d
-
- 1 eq exch % Stack is: a b d==1 c
- 0 eq and exch % Stack is: a {c==0 && d==1} b
- 0 eq and exch % Stack is: {b==0 && c==0 && d==1} a
- 1 eq and % Stack is: {a==1 && b==0 && c==0 && d==1}
-
- /isSimpleTranslation Xdef
-
- } ifelse
-
- currentdict % Leave a copy of the dictionary on the stack.
- end
-
- } Bdef
-
-
- %<FF>
- % The SetTr proc:
- %
- % Takes a transform dictionary and makes the graphics state reflect its contents.
- %
- % trDict SetTr -
- %
- % trDict: A valid transform dictionary. Usually created by MakeTrDict.
- %
- /SetTr {
- begin % Put the transform dictionary at the top of the dictionary stack.
-
- Mapping concat % Concatonate the transform's mapping with the CTM
- TrSetClip % Set the clip.
-
- end % Remove the transform dictionary from the dictionary stack.
-
- } Bdef
-