shithub: riscv

ref: 84e019aba3dd233d817272cc62ca2a95a5263de7
dir: /sys/src/cmd/postscript/postmd/postmd.ps/

View raw version
%
% Version 3.3.2 prologue for matrix display files.
%

/#copies 1 store
/aspectratio 1 def
/font /Helvetica def
/formsperpage 1 def
/landscape false def
/magnification 1 def
/margin 10 def
/orientation 0 def
/rotation 1 def
/size 9 def
/statspace 1.6 def
/ticklength .06 def
/tickspacing 10 def
/xoffset 0 def
/yoffset 0 def

/useclippath true def
/pagebbox [0 0 612 792] def

/inch {72 mul} bind def
/min {2 copy gt {exch} if pop} bind def

/show {show} bind def		% so later references don't bind
/stringwidth {stringwidth} bind def

/setup {
	counttomark 2 idiv {def} repeat pop

	landscape {/orientation 90 orientation add def} if

	pagedimensions
	height width lt {
		/statspace statspace height width div mul def
		/size size height width div mul def
		/ticklength ticklength height width div mul def
	} if
	/height height margin sub statspace inch sub ticklength inch sub size 6 mul sub def
	/width width margin sub ticklength inch sub def
	xcenter ycenter translate
	orientation rotation mul rotate
	xoffset inch yoffset inch translate
	0 height 2 div height width min 2 div sub translate
	0 statspace inch 2 div translate
	magnification dup aspectratio mul scale

	0 setlinewidth
} def

/pagedimensions {
	useclippath {
		/pagebbox [clippath pathbbox newpath] def
	} if
	pagebbox aload pop
	4 -1 roll exch 4 1 roll 4 copy
	landscape {4 2 roll} if
	sub /width exch def
	sub /height exch def
	add 2 div /xcenter exch def
	add 2 div /ycenter exch def
	userdict /gotpagebbox true put
} def

/pagesetup {/page exch def} bind def

/bitmap {
	/scanlines exch def
	/scanlength exch def

	/picstr scanlength string def

	gsave
	height scanlines div width scanlength div min
	/scaling exch def
	scaling scaling scale

	scanlength neg 2 div scanlines neg 2 div translate
	scanlength scanlines scale
	getbitmap
	grestore
} bind def

/getbitmap {
	scanlength scanlines 8 [scanlength 0 0 scanlines neg 0 scanlines] {
		0 {
			currentfile token pop dup
			0 eq {pop pop exit} if
			/charcount exch def
			picstr 1 index charcount getinterval
			/repl exch def
			currentfile repl readhexstring pop pop
			charcount add
			currentfile token pop {
				picstr 1 index repl putinterval
				charcount add
			} repeat
		} loop
		picstr
	} image
} bind def

/labelmatrix {
	/matrixlimits exch def
	/matrixname exch def

	gsave
	scaling scaling scale
	font findfont size scaling div scalefont setfont
	scanlength neg 2 div scanlines 2 div translate

	0 scanlines size 1.5 mul scaling div add neg moveto
	matrixname show

	scanlength scanlines size 1.5 mul scaling div add neg moveto
	matrixlimits stringwidth pop neg 0 rmoveto
	matrixlimits show

	newpath
	0 0 moveto
	scanlength 0 rlineto
	0 scanlines neg rlineto
	scanlength neg 0 rlineto
	closepath stroke

	scanlength tickspacing idiv 1 add tickspacing 0 ticks
	scanlines tickspacing idiv 1 add 0 tickspacing neg ticks
	grestore
} bind def

/ticks {
	/dy exch def
	/dx exch def

	/tl ticklength inch scaling div def
	newpath
	0 0 moveto
	{
		gsave dx 0 eq {tl neg 0} {0 tl} ifelse rlineto stroke grestore
		dx dy rmoveto
	} repeat
} bind def

/legend {
	/regions exch def
	/total exch def

	gsave
	width height min 2 div neg dup size 2 mul sub translate
	0 statspace inch neg translate

	gsave
	regions {
		gsave
		total div statspace inch size 2 mul sub mul size 2 mul add
		width height min regions div exch scale
		1 1 8 [1 0 0 1 0 0] 5 -1 roll image
		grestore
		width height min regions div 0 translate
	} repeat
	grestore

	width height min size 1.5 mul neg translate
	font findfont size scalefont setfont
	dup dup add 1 add width height min exch div /interval exch def
	{
    		interval neg 0 translate
		interval 2 div neg 0 translate
    		dup stringwidth pop 2 div neg 0 moveto show
		interval 2 div neg 0 translate
	} repeat
	grestore
} bind def

/done {/lastpage where {pop lastpage} if} def