/* Copyright (C) 1989, 1992 Aladdin Enterprises. All rights reserved.
Distributed by Free Software Foundation, Inc.
This file is part of Ghostscript.
Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing. Refer
to the Ghostscript General Public License for full details.
Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License. A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities. It should be in a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
/* Graphics state operators for Ghostscript */
private int near
num_param(P2(os_ptr
, int (*)(P2(gs_state
*, floatp
))));
private int near
line_param(P2(os_ptr
, int *));
/* The current graphics state */
/* Initialize the graphics stack. */
{ igs
= gs_state_alloc(alloc
, alloc_free
);
make_null(&istate
.screen_proc
);
make_null(&istate
.transfer_procs
.red
);
make_null(&istate
.transfer_procs
.green
);
make_null(&istate
.transfer_procs
.blue
);
make_null(&istate
.transfer_procs
.gray
);
/* gsave and grestore only work properly */
/* if there are always at least 2 entries on the stack. */
/* We count on the PostScript initialization code to do a gsave. */
zgsave(register os_ptr op
)
{ int_gstate
*pis
= (int_gstate
*)alloc(1, sizeof(int_gstate
), "gsave");
if ( pis
== 0 ) return e_VMerror
;
{ alloc_free((char *)pis
, 1, sizeof(int_gstate
), "gsave");
zgrestore(register os_ptr op
)
{ int code
= gs_grestore(igs
);
if ( code
< 0 ) return code
;
alloc_free((char *)pis
, 1, sizeof(int_gstate
), "grestore");
else /* bottom of stack */
zgrestoreall(register os_ptr op
)
{ while ( istate
.saved
->saved
)
{ int code
= zgrestore(op
);
if ( code
< 0 ) return code
;
zinitgraphics(register os_ptr op
)
{ return gs_initgraphics(igs
);
zsetlinewidth(register os_ptr op
)
{ return num_param(op
, gs_setlinewidth
);
zcurrentlinewidth(register os_ptr op
)
make_real(op
, gs_currentlinewidth(igs
));
zsetlinecap(register os_ptr op
)
int code
= line_param(op
, ¶m
);
if ( !code
) code
= gs_setlinecap(igs
, (gs_line_cap
)param
);
zcurrentlinecap(register os_ptr op
)
make_int(op
, (int)gs_currentlinecap(igs
));
zsetlinejoin(register os_ptr op
)
int code
= line_param(op
, ¶m
);
if ( !code
) code
= gs_setlinejoin(igs
, (gs_line_join
)param
);
zcurrentlinejoin(register os_ptr op
)
make_int(op
, (int)gs_currentlinejoin(igs
));
zsetmiterlimit(register os_ptr op
)
{ return num_param(op
, gs_setmiterlimit
);
zcurrentmiterlimit(register os_ptr op
)
make_real(op
, gs_currentmiterlimit(igs
));
zsetdash(register os_ptr op
)
int code
= real_param(op
, &offset
);
/* Unpack the dash pattern and check it */
dfrom
= op
[-1].value
.refs
;
pattern
= dto
= (float *)alloc(n
, sizeof(float), "setdash");
{ switch ( r_type(dfrom
) )
*dto
++ = dfrom
->value
.intval
;
*dto
++ = dfrom
->value
.realval
;
alloc_free((char *)dto
, n
, sizeof(float), "setdash");
code
= gs_setdash(igs
, pattern
, n
, offset
);
zcurrentdash(register os_ptr op
)
{ int n
= gs_currentdash_length(igs
);
ref
*pattern
= alloc_refs(n
, "currentdash");
float *dfrom
= (float *)((char *)pattern
+ n
* (sizeof(ref
) - sizeof(float)));
gs_currentdash_pattern(igs
, dfrom
);
{ make_real(dto
, *dfrom
);
make_tasv(op
- 1, t_array
, a_all
, n
, refs
, pattern
);
make_real(op
, gs_currentdash_offset(igs
));
zsetflat(register os_ptr op
)
{ return num_param(op
, gs_setflat
);
zcurrentflat(register os_ptr op
)
make_real(op
, gs_currentflat(igs
));
/* ------ Initialization procedure ------ */
op_def zgstate_op_defs
[] = {
{"0currentdash", zcurrentdash
},
{"0currentflat", zcurrentflat
},
{"0currentlinecap", zcurrentlinecap
},
{"0currentlinejoin", zcurrentlinejoin
},
{"0currentlinewidth", zcurrentlinewidth
},
{"0currentmiterlimit", zcurrentmiterlimit
},
{"0grestore", zgrestore
},
{"0grestoreall", zgrestoreall
},
{"0initgraphics", zinitgraphics
},
{"1setlinecap", zsetlinecap
},
{"1setlinejoin", zsetlinejoin
},
{"1setlinewidth", zsetlinewidth
},
{"1setmiterlimit", zsetmiterlimit
},
/* ------ Internal routines ------ */
/* Get a numeric parameter */
num_param(os_ptr op
, int (*pproc
)(P2(gs_state
*, floatp
)))
int code
= real_param(op
, ¶m
);
if ( !code
) code
= (*pproc
)(igs
, param
);
/* Get an integer parameter 0-2. */
line_param(register os_ptr op
, int *pparam
)
{ check_type(*op
, t_integer
);
if ( op
->value
.intval
< 0 || op
->value
.intval
> 2 )
*pparam
= (int)op
->value
.intval
;