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 
dc_copy(wmfAPI * API,wmfDC * dc)23 static wmfDC* dc_copy (wmfAPI* API,wmfDC* dc)
24 {	wmfPlayer_t*          P  = (wmfPlayer_t*)          API->player_data;
25 	wmfFunctionReference* FR = (wmfFunctionReference*) API->function_reference;
26 
27 	wmfDC* dc_new = 0;
28 
29 	wmfRegion* clip;
30 	wmfRegion* clip_new;
31 
32 	wmfUserData_t userdata;
33 
34 	dc_new = (wmfDC*) wmf_malloc (API,sizeof (wmfDC));
35 
36 	if (ERR (API))
37 	{	WMF_DEBUG (API,"bailing...");
38 		return (0);
39 	}
40 
41 	dc_new->clip = wmf_malloc (API,sizeof (wmfRegion));
42 
43 	if (ERR (API))
44 	{	WMF_DEBUG (API,"bailing...");
45 		wmf_free (API,dc_new);
46 		return (0);
47 	}
48 
49 	clip_new = (wmfRegion*) dc_new->clip;
50 
51 	clip_new->numRects = 0;
52 	clip_new->size = 8;
53 	clip_new->rects = (wmfD_Rect*) wmf_malloc (API,clip_new->size * sizeof (wmfD_Rect));
54 
55 	if (ERR (API))
56 	{	WMF_DEBUG (API,"bailing...");
57 		wmf_free (API,dc_new->clip);
58 		wmf_free (API,dc_new);
59 		return (0);
60 	}
61 
62 	WMF_DC_SET_BACKGROUND (dc_new,&wmf_white);
63 	WMF_DC_SET_TEXTCOLOR  (dc_new,&wmf_black);
64 
65 	WMF_DC_SET_OPAQUE (dc_new);
66 
67 	WMF_DC_SET_POLYFILL (dc_new,ALTERNATE);
68 
69 	WMF_DC_SET_ROP (dc_new,R2_COPYPEN);
70 
71 	WMF_DC_SET_TEXTALIGN (dc_new,TA_LEFT);
72 
73 	WMF_DC_SET_CHAREXTRA  (dc_new,0);
74 	WMF_DC_SET_BREAKEXTRA (dc_new,0);
75 
76 	if (dc)
77 	{	WMF_DC_SET_BRUSH (dc_new,dc->brush);
78 		WMF_DC_SET_PEN   (dc_new,dc->pen  );
79 		WMF_DC_SET_FONT  (dc_new,dc->font );
80 
81 		clip = (wmfRegion*) dc->clip;
82 
83 		REGION_CopyRegion (API,clip_new,clip);
84 
85 		dc_new->Window.Ox = dc->Window.Ox;
86 		dc_new->Window.Oy = dc->Window.Oy;
87 
88 		dc_new->Window.width  = dc->Window.width;
89 		dc_new->Window.height = dc->Window.height;
90 
91 		dc_new->pixel_width  = dc->pixel_width;
92 		dc_new->pixel_height = dc->pixel_height;
93 
94 		dc_new->map_mode = dc->map_mode;
95 
96 		userdata.dc = P->dc;
97 		userdata.data = P->dc->userdata;
98 
99 		if (PLAY (API) && FR->udata_copy) FR->udata_copy (API,&userdata);
100 
101 		dc_new->userdata = userdata.data;
102 	}
103 	else
104 	{	SetDefaults (API,&(P->default_pen),&(P->default_brush),&(P->default_font));
105 
106 		WMF_DC_SET_BRUSH (dc_new,&(P->default_brush));
107 		WMF_DC_SET_PEN   (dc_new,&(P->default_pen  ));
108 		WMF_DC_SET_FONT  (dc_new,&(P->default_font ));
109 
110 		dc_new->Window.Ox = 0;
111 		dc_new->Window.Oy = 0;
112 
113 		dc_new->Window.width  = 1024;
114 		dc_new->Window.height = 1024;
115 
116 		dc_new->pixel_width  = 1;
117 		dc_new->pixel_height = 1;
118 
119 		dc_new->map_mode = MM_TEXT;
120 
121 		userdata.dc = dc_new;
122 		userdata.data = 0;
123 
124 		if (PLAY (API) && FR->udata_init) FR->udata_init (API,&userdata);
125 
126 		dc_new->userdata = userdata.data;
127 	}
128 
129 	return (dc_new);
130 }
131 
dc_stack_push(wmfAPI * API,wmfDC * dc)132 static void dc_stack_push (wmfAPI* API,wmfDC* dc)
133 {	wmfPlayer_t* P = (wmfPlayer_t*) API->player_data;
134 
135 	wmfDC** more = 0;
136 
137 	if (ERR (API)) return;
138 
139 	if (dc == 0)
140 	{	API->err = wmf_E_Glitch;
141 		return;
142 	}
143 
144 	if (P->dc_stack == 0)
145 	{	P->dc_stack = (wmfDC**) wmf_malloc (API,8 * sizeof (wmfDC*));
146 
147 		if (ERR (API)) return;
148 
149 		P->dc_stack_maxlen = 8;
150 	}
151 
152 	if (P->dc_stack_length == P->dc_stack_maxlen)
153 	{	more =  (wmfDC**) wmf_realloc (API,P->dc_stack,(P->dc_stack_maxlen + 8) * sizeof (wmfDC*));
154 
155 		if (ERR (API)) return;
156 
157 		P->dc_stack = more;
158 		P->dc_stack_maxlen += 8;
159 	}
160 
161 	P->dc_stack[P->dc_stack_length] = dc;
162 	P->dc_stack_length++;
163 }
164 
dc_stack_pop(wmfAPI * API)165 static wmfDC* dc_stack_pop (wmfAPI* API)
166 {	wmfPlayer_t* P = (wmfPlayer_t*) API->player_data;
167 
168 	if (ERR (API)) return (0);
169 
170 	if (P->dc_stack_length == 0)
171 	{	API->err = wmf_E_Glitch;
172 		return (0);
173 	}
174 
175 	P->dc_stack_length--;
176 
177 	return (P->dc_stack[P->dc_stack_length]);
178 }
179 
dc_stack_free(wmfAPI * API)180 static void dc_stack_free (wmfAPI* API)
181 {	wmfPlayer_t* P = (wmfPlayer_t*) API->player_data;
182 
183 	while (P->dc_stack_length)
184 	{	P->dc_stack_length--;
185 		wmf_free (API,P->dc_stack[P->dc_stack_length]);
186 	}
187 
188 	wmf_free (API,P->dc_stack);
189 
190 	P->dc_stack = 0;
191 	P->dc_stack_maxlen = 0;
192 }
193 
194 #endif /* ! WMFPLAYER_DC_H */
195