/src/ghostpdl/pcl/pxl/pxstate.c
Line | Count | Source |
1 | | /* Copyright (C) 2001-2023 Artifex Software, Inc. |
2 | | All Rights Reserved. |
3 | | |
4 | | This software is provided AS-IS with no warranty, either express or |
5 | | implied. |
6 | | |
7 | | This software is distributed under license and may not be copied, |
8 | | modified or distributed except as expressly authorized under the terms |
9 | | of the license contained in the file LICENSE in this distribution. |
10 | | |
11 | | Refer to licensing information at http://www.artifex.com or contact |
12 | | Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, |
13 | | CA 94129, USA, for further information. |
14 | | */ |
15 | | |
16 | | |
17 | | /* pxstate.c */ |
18 | | /* State allocation/initialization/cleanup */ |
19 | | |
20 | | #include "stdio_.h" /* std.h + NULL */ |
21 | | #include "gstypes.h" |
22 | | #include "gsmemory.h" |
23 | | #include "gsstruct.h" |
24 | | #include "scommon.h" |
25 | | #include "pxparse.h" |
26 | | #include "pxstate.h" |
27 | | #include "pxfont.h" |
28 | | #include "gsfont.h" |
29 | | #include "gxfcache.h" |
30 | | |
31 | | /* Allocate a px_state_t. */ |
32 | | px_state_t * |
33 | | px_state_alloc(gs_memory_t * memory) |
34 | 8.09k | { |
35 | 8.09k | px_state_t *pxs = (px_state_t *) gs_alloc_bytes(memory, |
36 | 8.09k | sizeof(px_state_t), |
37 | 8.09k | "px_state_alloc"); |
38 | 8.09k | px_gstate_t *pxgs = px_gstate_alloc(memory); |
39 | | |
40 | 8.09k | if (pxs == 0 || pxgs == 0) |
41 | 0 | goto fail; |
42 | | |
43 | 8.09k | pxs->memory = memory; |
44 | 8.09k | pxs->pxgs = pxgs; |
45 | 8.09k | pxgs->pxs = pxs; |
46 | 8.09k | px_state_init(pxs, NULL); |
47 | | |
48 | | /* allocate the font directory */ |
49 | 8.09k | pxs->font_dir = gs_font_dir_alloc(pxs->memory); |
50 | 8.09k | if (pxs->font_dir == 0) |
51 | 0 | goto fail; |
52 | | |
53 | 8.09k | pxs->pcs = NULL; |
54 | 8.09k | pxs->this_pass_contiguous = false; |
55 | 8.09k | pxs->pass_first = true; |
56 | | |
57 | 8.09k | return pxs; |
58 | | |
59 | 0 | fail: |
60 | 0 | gs_free_object(memory, pxgs, "px_gstate_alloc"); |
61 | 0 | gs_free_object(memory, pxs, "px_state_alloc"); |
62 | 0 | return 0; |
63 | 8.09k | } |
64 | | |
65 | | /* Release a px_state_t */ |
66 | | void |
67 | | px_state_release(px_state_t * pxs) |
68 | 8.09k | { |
69 | | /* free the font dictionary */ |
70 | 8.09k | px_dict_release(&pxs->font_dict); |
71 | 8.09k | gs_free_object(pxs->memory, pxs->font_dir, "font_dir_alloc(dir)"); |
72 | | /* Don't free pxgs since it'll get freed as pgs' client */ |
73 | 8.09k | gs_free_object(pxs->memory, pxs, "px_state_release"); |
74 | 8.09k | } |
75 | | |
76 | | /* Do one-time state initialization. */ |
77 | | /* There isn't much of this: most state is initialized per-session. */ |
78 | | void |
79 | | px_state_init(px_state_t * pxs, gs_gstate * pgs) |
80 | 16.1k | { |
81 | 16.1k | pxs->pgs = pgs; |
82 | 16.1k | px_gstate_init(pxs->pxgs, pgs); |
83 | 16.1k | pxs->error_report = eErrorPage; /* default before first session */ |
84 | 16.1k | pxs->end_page = px_default_end_page; |
85 | 16.1k | pxs->data_source_open = false; |
86 | 16.1k | px_dict_init(&pxs->stream_dict, pxs->memory, NULL); |
87 | 16.1k | px_dict_init(&pxs->builtin_font_dict, pxs->memory, px_free_font); |
88 | 16.1k | px_dict_init(&pxs->font_dict, pxs->memory, px_free_font); |
89 | 16.1k | px_dict_init(&pxs->page_pattern_dict, pxs->memory, px_free_pattern); |
90 | 16.1k | px_dict_init(&pxs->session_pattern_dict, pxs->memory, px_free_pattern); |
91 | 16.1k | pxs->have_page = false; |
92 | 16.1k | pxs->warning_length = 0; |
93 | 16.1k | } |
94 | | |
95 | | /* Do one-time finalization at the end of execution. */ |
96 | | void |
97 | | px_state_finit(px_state_t * pxs) |
98 | 8.09k | { |
99 | | /* If streams persisted across sessions, we would release them here. */ |
100 | | #if 0 |
101 | | px_dict_release(&pxs->stream_dict); |
102 | | #endif |
103 | 8.09k | } |