/src/libwmf/src/player/dc.h
Line | Count | Source |
1 | | /* libwmf ("player/dc.h"): library for wmf conversion |
2 | | Copyright (C) 2000 - various; see CREDITS, ChangeLog, and sources |
3 | | |
4 | | The libwmf Library is free software; you can redistribute it and/or |
5 | | modify it under the terms of the GNU Library General Public License as |
6 | | published by the Free Software Foundation; either version 2 of the |
7 | | License, or (at your option) any later version. |
8 | | |
9 | | The libwmf Library is distributed in the hope that it will be useful, |
10 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | | Library General Public License for more details. |
13 | | |
14 | | You should have received a copy of the GNU Library General Public |
15 | | License along with the libwmf Library; see the file COPYING. If not, |
16 | | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | | Boston, MA 02111-1307, USA. */ |
18 | | |
19 | | |
20 | | #ifndef WMFPLAYER_DC_H |
21 | | #define WMFPLAYER_DC_H |
22 | | |
23 | | static wmfDC* dc_copy (wmfAPI* API,wmfDC* dc) |
24 | 17.1k | { wmfPlayer_t* P = (wmfPlayer_t*) API->player_data; |
25 | 17.1k | wmfFunctionReference* FR = (wmfFunctionReference*) API->function_reference; |
26 | | |
27 | 17.1k | wmfDC* dc_new = 0; |
28 | | |
29 | 17.1k | wmfRegion* clip; |
30 | 17.1k | wmfRegion* clip_new; |
31 | | |
32 | 17.1k | wmfUserData_t userdata; |
33 | | |
34 | 17.1k | dc_new = (wmfDC*) wmf_malloc (API,sizeof (wmfDC)); |
35 | | |
36 | 17.1k | if (ERR (API)) |
37 | 0 | { WMF_DEBUG (API,"bailing..."); |
38 | 0 | return (0); |
39 | 0 | } |
40 | | |
41 | 17.1k | dc_new->clip = wmf_malloc (API,sizeof (wmfRegion)); |
42 | | |
43 | 17.1k | if (ERR (API)) |
44 | 0 | { WMF_DEBUG (API,"bailing..."); |
45 | 0 | wmf_free (API,dc_new); |
46 | 0 | return (0); |
47 | 0 | } |
48 | | |
49 | 17.1k | clip_new = (wmfRegion*) dc_new->clip; |
50 | | |
51 | 17.1k | clip_new->numRects = 0; |
52 | 17.1k | clip_new->size = 8; |
53 | 17.1k | clip_new->rects = (wmfD_Rect*) wmf_malloc (API,clip_new->size * sizeof (wmfD_Rect)); |
54 | | |
55 | 17.1k | if (ERR (API)) |
56 | 0 | { WMF_DEBUG (API,"bailing..."); |
57 | 0 | wmf_free (API,dc_new->clip); |
58 | 0 | wmf_free (API,dc_new); |
59 | 0 | return (0); |
60 | 0 | } |
61 | | |
62 | 17.1k | WMF_DC_SET_BACKGROUND (dc_new,&wmf_white); |
63 | 17.1k | WMF_DC_SET_TEXTCOLOR (dc_new,&wmf_black); |
64 | | |
65 | 17.1k | WMF_DC_SET_OPAQUE (dc_new); |
66 | | |
67 | 17.1k | WMF_DC_SET_POLYFILL (dc_new,ALTERNATE); |
68 | | |
69 | 17.1k | WMF_DC_SET_ROP (dc_new,R2_COPYPEN); |
70 | | |
71 | 17.1k | WMF_DC_SET_TEXTALIGN (dc_new,TA_LEFT); |
72 | | |
73 | 17.1k | WMF_DC_SET_CHAREXTRA (dc_new,0); |
74 | 17.1k | WMF_DC_SET_BREAKEXTRA (dc_new,0); |
75 | | |
76 | 17.1k | if (dc) |
77 | 2.65k | { WMF_DC_SET_BRUSH (dc_new,dc->brush); |
78 | 2.65k | WMF_DC_SET_PEN (dc_new,dc->pen ); |
79 | 2.65k | WMF_DC_SET_FONT (dc_new,dc->font ); |
80 | | |
81 | 2.65k | clip = (wmfRegion*) dc->clip; |
82 | | |
83 | 2.65k | REGION_CopyRegion (API,clip_new,clip); |
84 | | |
85 | 2.65k | dc_new->Window.Ox = dc->Window.Ox; |
86 | 2.65k | dc_new->Window.Oy = dc->Window.Oy; |
87 | | |
88 | 2.65k | dc_new->Window.width = dc->Window.width; |
89 | 2.65k | dc_new->Window.height = dc->Window.height; |
90 | | |
91 | 2.65k | dc_new->pixel_width = dc->pixel_width; |
92 | 2.65k | dc_new->pixel_height = dc->pixel_height; |
93 | | |
94 | 2.65k | dc_new->map_mode = dc->map_mode; |
95 | | |
96 | 2.65k | userdata.dc = P->dc; |
97 | 2.65k | userdata.data = P->dc->userdata; |
98 | | |
99 | 2.65k | if (PLAY (API) && FR->udata_copy) FR->udata_copy (API,&userdata); |
100 | | |
101 | 2.65k | dc_new->userdata = userdata.data; |
102 | 2.65k | } |
103 | 14.5k | else |
104 | 14.5k | { SetDefaults (API,&(P->default_pen),&(P->default_brush),&(P->default_font)); |
105 | | |
106 | 14.5k | WMF_DC_SET_BRUSH (dc_new,&(P->default_brush)); |
107 | 14.5k | WMF_DC_SET_PEN (dc_new,&(P->default_pen )); |
108 | 14.5k | WMF_DC_SET_FONT (dc_new,&(P->default_font )); |
109 | | |
110 | 14.5k | dc_new->Window.Ox = 0; |
111 | 14.5k | dc_new->Window.Oy = 0; |
112 | | |
113 | 14.5k | dc_new->Window.width = 1024; |
114 | 14.5k | dc_new->Window.height = 1024; |
115 | | |
116 | 14.5k | dc_new->pixel_width = 1; |
117 | 14.5k | dc_new->pixel_height = 1; |
118 | | |
119 | 14.5k | dc_new->map_mode = MM_TEXT; |
120 | | |
121 | 14.5k | userdata.dc = dc_new; |
122 | 14.5k | userdata.data = 0; |
123 | | |
124 | 14.5k | if (PLAY (API) && FR->udata_init) FR->udata_init (API,&userdata); |
125 | | |
126 | 14.5k | dc_new->userdata = userdata.data; |
127 | 14.5k | } |
128 | | |
129 | 17.1k | return (dc_new); |
130 | 17.1k | } |
131 | | |
132 | | static void dc_stack_push (wmfAPI* API,wmfDC* dc) |
133 | 2.65k | { wmfPlayer_t* P = (wmfPlayer_t*) API->player_data; |
134 | | |
135 | 2.65k | wmfDC** more = 0; |
136 | | |
137 | 2.65k | if (ERR (API)) return; |
138 | | |
139 | 2.65k | if (dc == 0) |
140 | 0 | { API->err = wmf_E_Glitch; |
141 | 0 | return; |
142 | 0 | } |
143 | | |
144 | 2.65k | if (P->dc_stack == 0) |
145 | 406 | { P->dc_stack = (wmfDC**) wmf_malloc (API,8 * sizeof (wmfDC*)); |
146 | | |
147 | 406 | if (ERR (API)) return; |
148 | | |
149 | 406 | P->dc_stack_maxlen = 8; |
150 | 406 | } |
151 | | |
152 | 2.65k | if (P->dc_stack_length == P->dc_stack_maxlen) |
153 | 179 | { more = (wmfDC**) wmf_realloc (API,P->dc_stack,(P->dc_stack_maxlen + 8) * sizeof (wmfDC*)); |
154 | | |
155 | 179 | if (ERR (API)) return; |
156 | | |
157 | 179 | P->dc_stack = more; |
158 | 179 | P->dc_stack_maxlen += 8; |
159 | 179 | } |
160 | | |
161 | 2.65k | P->dc_stack[P->dc_stack_length] = dc; |
162 | 2.65k | P->dc_stack_length++; |
163 | 2.65k | } |
164 | | |
165 | | static wmfDC* dc_stack_pop (wmfAPI* API) |
166 | 2.38k | { wmfPlayer_t* P = (wmfPlayer_t*) API->player_data; |
167 | | |
168 | 2.38k | if (ERR (API)) return (0); |
169 | | |
170 | 2.38k | if (P->dc_stack_length == 0) |
171 | 1 | { API->err = wmf_E_Glitch; |
172 | 1 | return (0); |
173 | 1 | } |
174 | | |
175 | 2.37k | P->dc_stack_length--; |
176 | | |
177 | 2.37k | return (P->dc_stack[P->dc_stack_length]); |
178 | 2.38k | } |
179 | | |
180 | | static void dc_stack_free (wmfAPI* API) |
181 | 12.4k | { wmfPlayer_t* P = (wmfPlayer_t*) API->player_data; |
182 | | |
183 | 12.4k | while (P->dc_stack_length) |
184 | 0 | { P->dc_stack_length--; |
185 | 0 | wmf_free (API,P->dc_stack[P->dc_stack_length]); |
186 | 0 | } |
187 | | |
188 | 12.4k | wmf_free (API,P->dc_stack); |
189 | | |
190 | 12.4k | P->dc_stack = 0; |
191 | 12.4k | P->dc_stack_maxlen = 0; |
192 | 12.4k | } |
193 | | |
194 | | #endif /* ! WMFPLAYER_DC_H */ |