1 /* libwmf ("player/record.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_RECORD_H
21 #define WMFPLAYER_RECORD_H
22 
ParU16(wmfAPI * API,wmfRecord * record,unsigned long index)23 static U16 ParU16 (wmfAPI* API,wmfRecord* record,unsigned long index)
24 {	U16 sp1;
25 	U16 sp2;
26 
27 	if (index >= record->size)
28 	{	WMF_ERROR (API,"Bad record - unexpectedly short!");
29 		API->err = wmf_E_BadFormat;
30 		return (0);
31 	}
32 
33 	index <<= 1;
34 	sp1 = record->parameter[index];
35 	index++;
36 	sp2 = record->parameter[index];
37 
38 	return ((sp2 << 8) | sp1);
39 }
40 
PutParU16(wmfAPI * API,wmfRecord * record,unsigned long index,U16 sp)41 static int PutParU16 (wmfAPI* API,wmfRecord* record,unsigned long index,U16 sp)
42 {	int changed = 0;
43 
44 	unsigned char c1 = (unsigned char) ( sp       & 0xff);
45 	unsigned char c2 = (unsigned char) ((sp >> 8) & 0xff);
46 
47 	if (index >= record->size)
48 	{	WMF_ERROR (API,"Bad record - unexpectedly short!");
49 		API->err = wmf_E_BadFormat;
50 		return (0);
51 	}
52 
53 	index <<= 1;
54 	if (record->parameter[index] != c1)
55 	{	record->parameter[index] = c1;
56 		changed = 1;
57 	}
58 	index++;
59 	if (record->parameter[index] != c2)
60 	{	record->parameter[index] = c2;
61 		changed = 1;
62 	}
63 
64 	return (changed);
65 }
66 
ParS16(wmfAPI * API,wmfRecord * record,unsigned long index)67 static S16 ParS16 (wmfAPI* API,wmfRecord* record,unsigned long index)
68 {	U16 up;
69 
70 	up = ParU16 (API,record,index);
71 
72 	if (ERR (API))
73 	{	WMF_DEBUG (API,"bailing...");
74 		return (up);
75 	}
76 
77 	return (U16_2_S16 (up));
78 }
79 
ParS32(wmfAPI * API,wmfRecord * record,unsigned long index)80 static S32 ParS32 (wmfAPI* API,wmfRecord* record,unsigned long index)
81 {	U16 up;
82 
83 	up = ParU16 (API,record,index);
84 
85 	if (ERR (API))
86 	{	WMF_DEBUG (API,"bailing...");
87 		return (up);
88 	}
89 
90 	return (U16_2_S32 (up));
91 }
92 
OffsetRecord(wmfAPI * API,wmfRecord * record,unsigned long index)93 static wmfRecord OffsetRecord (wmfAPI* API,wmfRecord* record,unsigned long index)
94 {	wmfRecord new_record;
95 
96 	new_record.function = record->function;
97 	new_record.size = 0;
98 	new_record.parameter = 0;
99 	new_record.position = 0;
100 
101 	if (index > record->size)
102 	{	WMF_ERROR (API,"Bad record - unexpectedly short!");
103 		API->err = wmf_E_BadFormat;
104 		return (new_record);
105 	}
106 
107 	new_record.size = record->size - index;
108 	index <<= 1;
109 	new_record.parameter = record->parameter + index;
110 
111 	new_record.position = record->position + index;
112 
113 	return (new_record);
114 }
115 
116 #endif /* ! WMFPLAYER_RECORD_H */
117