🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #620

Re: User Path

#620
From: Larry Cordner
Date: Sat, 11 Apr 1992 21:45
62 lines
3026 bytes
In article <1992Apr11.091359.65305@yuma.acns.colostate.edu> ckminer@LANCE.ColoState.Edu (Chris Miner) writes:
>
>I've this code for a drawSelf:: implementation-
>
>- drawSelf:(const NXRect *)rects :(int)rectCount
>{
>	float coords[8] = {50.0, 50.0, 100.0, 0.0, 0.0, 100.0, -100.0, 0.0};
>	char ops[5] = {dps_moveto, dps_rlineto, 
>				dps_rlineto, dps_rlineto,
>				dps_closepath};
>	short bbox[4] = {0, 0, 200, 200};
>
>	PSsetgray(0.0);
>	NXRectFill(rects);
>	PSsetgray(1.0);
>	DPSDoUserPath(coords, 8, dps_float, ops, 5, bbox, dps_ustroke);
>	return self;
>}
>
>The problem is it only works for short coords and dps_short instead of
>float coords and dps_float.  I noticed the Draw, Graph and Lines
>examples use floats.  Any answers on this?


The easy answer is that the bbox argument should be defined as a float, if you
want to use, float coords, dps_float.  The types of bbox and coords, need to
be the same as the type passed to DPSDoUserPath().


The more difficult question is, why is this so?  The answer lies in the way 
DPSDoUserPath() processes its arguments.  DPSDoUserPath() takes its arguments
and turns them into an array that contains two PostScript binary object
sequences.  The first of these sequences is a concatenation of the bbox and
coords arguments, and its type is the type passed to DPSDoUserPath().  In your
example, the one that doesn't work, the type would be dps_float.  Since bbox
is defined as short, and it is encoded as type dps_float, bbox doesn't have
enough bytes in it, so random bytes are used to fill in.  (Actually the bytes
aren't random they're the eight bytes that follow bbox in memory.  In your
case, the first five bytes come from the ops array, and the other three come
from whatever is after the ops array in memory.)


It's the same old story, a function wants a float and you give it a short.  The
function doesn't know you only passed a short and grabs a float sized object.
Maybe the function survives maybe it doesn't.  In your case if you take a look
at the console, you'll see a bunch of DPS client library errors.

BTW: I could find no mention in the docs, that says the bbox, coords and the
type passed to DPSDoUserPath() all need to be the same.  But from what I've
seen they apparently do!



Hope this helps,

larry cordner
larry@netcom.com

P.S. If you need more details about what is going on, send me mail.
     I have a long and drawn out description of this, including a break down
     of the binary encoded user paths that are sent to the server, this really
     shows the problem.
Technical Details
Message-ID: <jcvj7g#.larry@netcom.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!csus.edu!netcomsv!mork!larry
References: <1992Apr11.091359.65305@yuma.acns.colostate.edu>

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!csus.edu!netcomsv!mork!larry
From: larry@netcom.com (Larry Cordner)
Subject: Re: User Path
Message-ID: <jcvj7g#.larry@netcom.com>
Date: Sat, 11 Apr 92 21:45:28 GMT
Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
References: <1992Apr11.091359.65305@yuma.acns.colostate.edu>
Keywords: DPSDoUserPath
Lines: 62