File:  [Research Unix] / researchv10no / cmd / postscript / dpost / ps_include.ps
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:35 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Norman

-> PS_head

%ps_include: begin
save
/ed {exch def} def

# redefine dangerous operators
{} /showpage ed
{} /copypage ed
{} /erasepage ed
{} /letter ed

# restore findfont from systemdict if it looks like it's be redefined
currentdict /findfont known systemdict /findfont known and {
	/findfont systemdict /findfont get def
} if

# computations are done in the context of a new dictionary
36 dict dup /PS-include-dict-dw ed begin

# context holds the save object created earlier
/context ed

# save and clear the operand stack
count array astore /o-stack ed

# the following variables are now expected:
#	llx,lly,urx,ury	bounding box of picture to be included
#	w		nonzero if space should be painted white to start
#	o		nonzero if space should be outlined
#	s		nonzero if both dimensions should be scaled
#	cx,cy		center of page space in current coordinates
#	sx,sy		size of page space in current coordinates
#	ax,ay		left-right, up-down adjustment of picture in page space
#	rot		rotation of picture in page space
%ps_include: variables begin



-> PS_setup

%ps_include: variables end

# some routines:
# - BBOX llx lly urx ury	put bounding box on stack
# llx lly urx ury BOXPATH -	make a path with given box corners
# dx dy LEN length		compute length of positionless vector
# a b MIN min			compute minimum of two numbers
# a b MAX max			compute maximum of two numbers
# x y NICE x y			move to pixel boundaries in default coords
{llx lly urx ury} /bbox ed
{newpath 2 index exch 2 index exch dup 6 index exch
 moveto 3 {lineto} repeat closepath} /boxpath ed
{dup mul exch dup mul add sqrt} /len ed
{2 copy gt {exch} if pop} /min ed
{2 copy lt {exch} if pop} /max ed
{transform round exch round exch A itransform} /nice ed

# A is the transformation from default to current coordinates
{6 array} /n ed
n defaultmatrix n currentmatrix n invertmatrix n concatmatrix /A ed

# Sx,Sy and Cx,Cy are dimensions and size of bounding box in current coordinates
urx llx sub 0 A dtransform len /Sx ed
0 ury lly sub A dtransform len /Sy ed
llx urx add 2 div lly ury add 2 div A transform /Cy ed /Cx ed

# H and W are height and width of rotated box in current coordinates
rot dup sin abs /S ed cos abs /C ed
Sx S mul Sy C mul add /H ed
Sx C mul Sy S mul add /W ed

# Scalex and Scaley are the required horizontal and vertical scaling factors
sy H div /Scaley ed
sx W div /Scalex ed

# Preserve aspect ratio if we're not scaling both dimensions (ie. s is 0)
s 0 eq {Scalex Scaley min dup /Scalex ed /Scaley ed} if

# add to cx,cy the shift needed within the page space
sx Scalex W mul sub 0 max ax 0.5 sub mul cx add /cx ed
sy Scaley H mul sub 0 max ay 0.5 sub mul cy add /cy ed

# the actual rotation needed is rot less the current rotation
urx llx sub 0 A dtransform exch atan rot exch sub /rot ed

# set up the coordinate system
n currentmatrix initgraphics setmatrix
cx cy translate
Scalex Scaley scale
rot rotate
Cx neg Cy neg translate
A concat

# set the clipping region, and conditionally whiteout and outline
bbox boxpath clip newpath
w 0 ne {gsave bbox boxpath 1 setgray fill grestore} if

# pop local dictionary from the dict stack
end

# now begins the actual material extracted from the file
gsave
%ps_include: inclusion begin



-> PS_tail

%ps_include: inclusion end
grestore

# within the context of the local dictionary ...
PS-include-dict-dw begin

o 0 ne {gsave A defaultmatrix /A ed llx lly nice urx ury nice
	initgraphics 0.1 setlinewidth boxpath stroke grestore} if

# ... restore the operand stack and the save context
clear o-stack aload pop
context end restore
%ps_include: end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.