summaryrefslogtreecommitdiff
path: root/pxl/pxstate.c
blob: 60d13090f7beab122ef86928b353ead57f221d83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* Portions Copyright (C) 2001 artofcode LLC.
   Portions Copyright (C) 1996, 2001 Artifex Software Inc.
   Portions Copyright (C) 1988, 2000 Aladdin Enterprises.
   This software is based in part on the work of the Independent JPEG Group.
   All Rights Reserved.

   This software is distributed under license and may not be copied, modified
   or distributed except as expressly authorized under the terms of that
   license.  Refer to licensing information at http://www.artifex.com/ or
   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
   San Rafael, CA  94903, (415)492-9861, for further information. */
/*$Id$ */

/* pxstate.c */
/* State allocation/initialization/cleanup */

#include "stdio_.h"			/* std.h + NULL */
#include "gstypes.h"
#include "gsmemory.h"
#include "gsstruct.h"
#include "scommon.h"
#include "pxparse.h"
#include "pxstate.h"
#include "pxfont.h"
#include "gxfcache.h"

/* Import the initialization procedure table from pxtop.c. */
typedef int (*px_init_proc)(px_state_t *);
extern const px_init_proc px_init_table[];

/* Allocate a px_state_t. */
px_state_t *
px_state_alloc(gs_memory_t *memory)
{	
    px_state_t *pxs = (px_state_t *)gs_alloc_bytes(memory,
                                                   sizeof(px_state_t),
                                                   "px_state_alloc");
    px_gstate_t *pxgs = px_gstate_alloc(memory);

    if ( pxs == 0 || pxgs == 0 ) { 
        gs_free_object(memory, pxgs, "px_gstate_alloc");
        gs_free_object(memory, pxs, "px_state_alloc");
        return 0;
    }
    pxs->memory = memory;
    pxs->pxgs = pxgs;
    pxgs->pxs = pxs;
    px_state_init(pxs, NULL);
    /* Run module initialization code. */
    { 
        const px_init_proc *init;
        for ( init = px_init_table; *init; ++init )
	    (*init)(pxs);
    }
    return pxs;
}

/* Release a px_state_t */
void
px_state_release(px_state_t *pxs)
{
    px_value_t val = {0}; /* arbitrary */
    /* delete the pxl error page and error page enumeration, the
       following deletes the font without having to import the font
       freeing procedure.  We add the font to the font dictionary and
       then release all of the fonts */
    px_dict_put(&pxs->font_dict, &val, pxs->error_page_font);
    px_dict_release(&pxs->font_dict);
    gs_free_object(pxs->memory, pxs->error_page_show_enum,
		   "px_state_release(pxs->error_page_show_enum)");
    /* Don't free pxgs since it'll get freed as pgs' client */
    gs_free_object(pxs->memory, pxs, "px_state_release");
}

/* Do one-time state initialization. */
/* There isn't much of this: most state is initialized per-session. */
void
px_state_init(px_state_t *pxs, gs_state *pgs)
{	pxs->pgs = pgs;
	px_gstate_init(pxs->pxgs, pgs);
	pxs->error_report = eErrorPage;	/* default before first session */
	pxs->end_page = px_default_end_page;
	pxs->data_source_open = false;
	px_dict_init(&pxs->stream_dict, pxs->memory, NULL);
	px_dict_init(&pxs->builtin_font_dict, pxs->memory, px_free_font);
	px_dict_init(&pxs->font_dict, pxs->memory, px_free_font);
	pxs->warning_length = 0;
}

/* Do one-time finalization at the end of execution. */
void
px_state_finit(px_state_t *pxs)
{	/* If streams persisted across sessions, we would release them here. */
#if 0
	px_dict_release(&pxs->stream_dict);
#endif
}