Thread View: comp.sys.next.programmer
2 messages
2 total messages
Started by Chris Miner
Sat, 11 Apr 1992 09:13
User Path
Author: Chris Miner
Date: Sat, 11 Apr 1992 09:13
Date: Sat, 11 Apr 1992 09:13
24 lines
1108 bytes
1108 bytes
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?
Chris
ckminer@longs.lance.colostate.edu
Re: User Path
Author: Larry Cordner
Date: Sat, 11 Apr 1992 21:45
Date: Sat, 11 Apr 1992 21:45
62 lines
3026 bytes
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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads