[comp.lang.postscript] Snap to Pixel Question

jwhiting@cdp.UUCP (08/17/89)

%% the following PostScript code has me baffled
%%
%% inch procedure
/in {72 mul } def
%%
%% procedure for line w/o snap procedure
%%
/NoSnap { 0 .125 in rlineto .045 in -.125 in rmoveto } bind def
%%
%% snap to pixel procedure from p148 Green Book
%%
/snap { transform round exch round exch itransform } bind def
%%
%% procedure for line w/Green Book snap procedure
%%
/WithSnap { 0 .125 in snap rlineto .045 in -.125 in snap rmoveto } bind def
%%
%% Aldus Prep snap trick
/Snap2
	{
	transform 2 div round 2 mul exch 2 div round 2 mul exch itransform
	} bind def
%%
%% procedure for line w/Aldus Prep snap
%%
/WithAldusSnap { 0 .125 in Snap2 rlineto .045 in -.125 in Snap2 rmoveto } bind
def
%%
200 200 moveto 35 { NoSnap } repeat
200 250 moveto 35 { WithSnap } repeat
200 300 moveto 35 { WithAldusSnap } repeat
.02 in setlinewidth stroke showpagesnap procedure?
%% this is no better: { transform .25 sub round .25 add round exch
%% .25 sub round .25 add round exchange itransform } bind def
%% the Aldus Prep snap trick gives a wiggle to the lines
%% what am I doing wrong?  I just want the lines & spaces to be even.
%% thanks           jwhiting
%% [DE3MIR]jwhiting via DASnet
%% UUCP: uunet!pyramid!cdp!jwhiting
%% Bitnet: cdp!jwhiting%labrea@stanford
%% Internet: cdp!jwhiting!@arisia.xerox.com

batcheldern@level.dec.com (Ned Batchelder) (08/24/89)

The problem you are having is that you are using snap with relative
operators. The snap procedures you are using think that they are dealing
with *locations*,
but the pair of numbers you are giving them are destined for the
r-flavor operators, so they are *displacements*. I think if you augment
your snap procedures with some relative versions, the problem will be fixed:

	/snap  {  transform 2 { round exch } repeat  itransform } def
	/rsnap { dtransform 2 { round exch } repeat idtransform } def

"snap" uses transform and itransform, which (from the Red Book) "...
transform the user space coordinate (x,y) ...". Rsnap uses dtransform
and idtransform, which "... transform the distance vector (dx, dy) ...".
The transform and dtransform operators exactly parallel the lineto and
rlineto operators, and now, the snap and rsnap procedures.

If you make sure to use snap for coordinates, and rsnap for
displacements, you should be ok.

Ned Batchelder, Digital Equipment Corp., BatchelderN@Hannah.DEC.com