home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
gnu
/
gs-2.6.1.4-src.lha
/
src
/
amiga
/
gs-2.6.1.4
/
gsstate.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-27
|
13KB
|
448 lines
/* Copyright (C) 1989, 1992 Aladdin Enterprises. All rights reserved.
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
copies. */
/* gsstate.c */
/* Miscellaneous graphics state operators for Ghostscript library */
#include "gx.h"
#include "memory_.h"
#include "gserrors.h"
#include "gxrefct.h" /* early for gscie.h */
#include "gxcolor.h" /* for gscolor2.h, gscie.h */
#include "gzstate.h"
#include "gzdevice.h"
#include "gscspace.h"
#include "gscolor2.h"
#include "gscie.h"
#include "gzcolor.h" /* requires gxdevice.h */
#include "gzht.h"
#include "gzline.h"
#include "gzpath.h"
/* Imported values */
/* The following should include a 'const', but */
/* the Watcom compiler won't accept it. */
extern /*const*/ gx_color_map_procs *cmap_procs_default;
/* Forward references */
private gs_state *alloc_gstate(P3(const gs_memory_procs *, const gs_state *,
const char *));
private int alloc_gstate_contents(P1(gs_state *));
private void free_gstate_contents(P1(gs_state *));
private void copy_gstate_contents(P2(gs_state *pto, const gs_state *pfrom));
/* The structure for allocating (most of) the contents of a gstate */
/* all at once. */
typedef struct gs_state_contents_s {
gx_path path;
gx_clip_path clip_path;
line_params line_params;
halftone_params halftone;
gs_color_space color_space;
gs_client_color ccolor;
gx_device_color dev_color;
} gs_state_contents;
#define gstate_contents(pgs) ((gs_state_contents *)((pgs)->path))
/* Allocate and free a structure */
#define alloc_struct(pgs,typ,cname)\
(typ *)(*(pgs)->memory_procs->alloc)(1, sizeof(typ), cname)
#define free_struct(pgs,ptr,cname)\
(*(pgs)->memory_procs->free)((char *)(ptr), 1, sizeof(*(ptr)), cname)
/* ------ Operations on the entire graphics state ------ */
/* Allocate and initialize a graphics state. */
private float
null_transfer(const gs_state *pgs, floatp gray)
{ return gray;
}
gs_state *
gs_state_alloc(const gs_memory_procs *mprocs)
{ register gs_state *pgs =
alloc_gstate(mprocs, (gs_state *)0, "gs_state_alloc");
if ( pgs == 0 ) return 0;
pgs->saved = 0;
/* Initialize things not covered by initgraphics */
gx_path_init(pgs->path, pgs->memory_procs);
gx_cpath_init(pgs->clip_path, pgs->memory_procs);
gx_alloc_ht_cache(pgs);
pgs->halftone->width = pgs->halftone->height =
pgs->halftone->order_size = 0;
gs_sethalftonephase(pgs, 0, 0);
/* Initialize things so that gx_remap_color won't crash. */
gx_set_black(pgs);
pgs->overprint = 0;
pgs->black_generation = 0;
pgs->undercolor_removal = 0;
pgs->cmap_procs = cmap_procs_default;
{ gx_transfer *ptran = &pgs->transfer;
rc_alloc_struct_n(ptran->gray, gx_transfer_map, mprocs,
return 0, "gs_state_alloc", 4);
ptran->red = ptran->green = ptran->blue = ptran->gray;
ptran->gray->proc = null_transfer;
ptran->gray->values[0] = frac_0;
}
gs_nulldevice(pgs);
gs_settransfer(pgs, null_transfer);
gs_setflat(pgs, 1.0);
gs_setstrokeadjust(pgs, 1);
/****** What about the font ? ******/
pgs->in_cachedevice = pgs->in_charpath = 0;
pgs->show_gstate = 0;
pgs->level = 0;
pgs->fill_adjust = float2fixed(0.25);
pgs->client_data = 0;
if ( gs_initgraphics(pgs) < 0 )
{ /* Something went very wrong */
return 0;
}
return pgs;
}
/* Set the client data in a graphics state. */
/* This should only be done to a newly created state. */
void
gs_state_set_client(gs_state *pgs, char/*void*/ *pdata,
const gs_state_client_procs *pprocs)
{ pgs->client_data = pdata;
pgs->client_procs = *pprocs;
}
/* Get the client data from a graphics state. */
char/*void*/ *
gs_state_client_data(gs_state *pgs)
{ return pgs->client_data;
}
/* Free a graphics state */
int
gs_state_free(gs_state *pgs)
{ free_gstate_contents(pgs);
free_struct(pgs, pgs, "gs_state_free");
return 0;
}
/* Save the graphics state */
int
gs_gsave(gs_state *pgs)
{ gs_state *pnew = alloc_struct(pgs, gs_state, "gs_gsave");
if ( pnew == 0 )
return_error(gs_error_VMerror);
*pnew = *pgs;
if ( alloc_gstate_contents(pgs) < 0 )
{ *pgs = *pnew; /* undo partial alloc */
free_struct(pgs, pnew, "gs_gsave");
return_error(gs_error_VMerror);
}
copy_gstate_contents(pgs, pnew);
/* Make pnew, not pgs, have the newly-allocated client data. */
{ char/*void*/ *pdata = pgs->client_data;
pgs->client_data = pnew->client_data;
pnew->client_data = pdata;
}
pgs->saved = pnew;
if ( pgs->show_gstate == pgs )
pgs->show_gstate = pnew->show_gstate = pnew;
pgs->level++;
if_debug2('g', "[g]gsave -> 0x%lx, level = %d\n",
(ulong)pnew, pgs->level);
return 0;
}
/* Restore the graphics state. */
int
gs_grestore(gs_state *pgs)
{ gs_state *saved = pgs->saved;
char/*void*/ *pdata = pgs->client_data;
char/*void*/ *sdata;
if_debug2('g', "[g]grestore 0x%lx, level was %d\n",
(ulong)saved, pgs->level);
if ( !saved ) return gs_gsave(pgs); /* shouldn't happen */
sdata = saved->client_data;
/* Swap back the client data pointers. */
pgs->client_data = sdata;
saved->client_data = pdata;
if ( pdata != 0 && sdata != 0 )
(*pgs->client_procs.copy)(pdata, sdata);
free_gstate_contents(pgs);
*pgs = *saved;
if ( pgs->show_gstate == saved )
pgs->show_gstate = pgs;
free_struct(pgs, saved, "gs_grestore");
return (pgs->saved == 0 ? gs_gsave(pgs) : 0);
}
/* Restore to the bottommost graphics state. */
int
gs_grestoreall(gs_state *pgs)
{ if ( !pgs->saved ) return gs_gsave(pgs); /* shouldn't happen */
while ( pgs->saved->saved ) gs_grestore(pgs);
return gs_grestore(pgs);
}
/* Allocate and return a new graphics state. */
gs_state *
gs_gstate(gs_state *pgs)
{ gs_state *pnew = alloc_gstate(pgs->memory_procs, pgs, "gs_gstate");
if ( pnew == 0 ) return 0;
copy_gstate_contents(pnew, pgs);
pnew->saved = 0;
return pnew;
}
/* Copy one previously allocated graphics state to another. */
int
gs_copygstate(gs_state *pto, const gs_state *pfrom)
{ /* This is the same as currentgstate. */
return gs_currentgstate(pto, pfrom);
}
/* Copy the current graphics state to a previously allocated one. */
int
gs_currentgstate(gs_state *pto, const gs_state *pgs)
{ /* We have to copy both the scalar and composite parts */
/* of the state. */
gs_state sgs;
sgs = *pto;
*pto = *pgs;
/* Put back the composite part pointers. */
#define gcopy(element)\
pto->element = sgs.element
gcopy(path);
gcopy(clip_path);
gcopy(line_params);
gcopy(halftone);
gcopy(color_space);
gcopy(ccolor);
gcopy(dev_color);
gcopy(cie_render);
gcopy(transfer.red);
gcopy(transfer.green);
gcopy(transfer.blue);
gcopy(transfer.gray);
gcopy(device);
gcopy(client_data);
#undef gcopy
copy_gstate_contents(pto, pgs);
return 0;
}
/* Restore the current graphics state from a previously allocated one. */
int
gs_setgstate(gs_state *pgs, const gs_state *pfrom)
{ /* The implementation is the same as currentgstate, */
/* except we must preserve the saved pointer and the level. */
gs_state *saved = pgs->saved;
int level = pgs->level;
int code = gs_currentgstate(pgs, pfrom);
if ( code < 0 ) return code;
pgs->saved = saved;
pgs->level = level;
return 0;
}
/* Swap the saved pointer of the graphics state. */
/* This is provided only for save/restore. */
gs_state *
gs_state_swap_saved(gs_state *pgs, gs_state *new_saved)
{ gs_state *saved = pgs->saved;
pgs->saved = new_saved;
return saved;
}
/* ------ Operations on components ------ */
/* Reset most of the graphics state */
int
gs_initgraphics(register gs_state *pgs)
{ int code;
gs_initmatrix(pgs);
if