source: trunk/gsdl/packages/wv-0.5.44-gs/src/fbse.c@ 1468

Last change on this file since 1468 was 1468, checked in by paynter, 24 years ago

The wv Packages from www.wvware.com is used to convert Word documents into
HTML. This is an adaptation of wv version 0.5.44 for greenstone; it is
called by the gsConvert.pl script.

  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1#include <stdlib.h>
2#include <stdio.h>
3#include "wv.h"
4
5void wvCopyBlip(Blip *dest,Blip *src)
6 {
7 int i;
8 wvCopyFBSE(&dest->fbse,&src->fbse);
9 dest->type = src->type;
10
11 if (src->name)
12 {
13 dest->name = (U16 *)malloc(src->fbse.cbName*sizeof(U16));
14 for(i=0;i<src->fbse.cbName;i++)
15 dest->name[i] = src->name[i];
16 }
17 else
18 dest->name=NULL;
19 switch(dest->type)
20 {
21 case msoblipWMF:
22 case msoblipEMF:
23 case msoblipPICT:
24 wvCopyMetafile(&dest->blip.metafile,&(src->blip.metafile));
25 break;
26 case msoblipJPEG:
27 case msoblipPNG:
28 case msoblipDIB:
29 wvCopyBitmap(&dest->blip.bitmap,&(src->blip.bitmap));
30 break;
31 }
32 }
33
34void wvReleaseBlip(Blip *blip)
35 {
36 wvFree(blip->name);
37 }
38
39U32 wvGetBlip(Blip *blip,FILE *fd,FILE *delay)
40 {
41 U32 i,count,count2;
42 MSOFBH amsofbh;
43 long pos=0;
44 count = wvGetFBSE(&blip->fbse,fd);
45 wvTrace(("count is %d\n",count));
46 if (blip->fbse.cbName == 0)
47 blip->name=NULL;
48 else
49 blip->name=(U16 *)malloc(sizeof(U16) * blip->fbse.cbName);
50 for(i=0;i<blip->fbse.cbName;i++)
51 blip->name[i] = read_16ubit(fd);
52 count+=blip->fbse.cbName*2;
53 wvTrace(("count is %d\n",count));
54 wvTrace(("offset %x\n",blip->fbse.foDelay));
55
56 if (delay)
57 {
58 pos = ftell(delay);
59 fseek(delay,blip->fbse.foDelay,SEEK_SET);
60 wvTrace(("offset %x\n",blip->fbse.foDelay));
61 fd = delay;
62 }
63
64 count2 = wvGetMSOFBH(&amsofbh,fd);
65 wvTrace(("count is %d\n",count2));
66 wvTrace(("HERE is %x %x (%d)\n",ftell(fd),amsofbh.fbt,amsofbh.fbt-msofbtBlipFirst));
67 wvTrace(("type is %x\n",amsofbh.fbt));
68 switch(amsofbh.fbt-msofbtBlipFirst)
69 {
70 case msoblipWMF:
71 case msoblipEMF:
72 case msoblipPICT:
73 count2 += wvGetMetafile(&blip->blip.metafile,&amsofbh,fd);
74 break;
75 case msoblipJPEG:
76 case msoblipPNG:
77 case msoblipDIB:
78 count2 += wvGetBitmap(&blip->blip.bitmap,&amsofbh,fd);
79 break;
80 }
81 wvTrace(("count is %d\n",count2));
82 blip->type = amsofbh.fbt-msofbtBlipFirst;
83
84 if (delay)
85 {
86 fseek(delay,pos,SEEK_SET);
87 return(count);
88 }
89
90 return(count+count2);
91 }
92
93U32 wvGetFBSE(FBSE *afbse,FILE *fd)
94 {
95 int i;
96 afbse->btWin32 = getc(fd);
97 afbse->btMacOS = getc(fd);
98 for (i=0;i<16;i++)
99 afbse->rgbUid[i] = getc(fd);
100 afbse->tag = read_16ubit(fd);
101 afbse->size = read_32ubit(fd);
102 afbse->cRef = read_32ubit(fd);
103 afbse->foDelay = read_32ubit(fd);
104 wvTrace(("location is %x, size is %d\n",afbse->foDelay,afbse->size));
105 afbse->usage = getc(fd);
106 afbse->cbName = getc(fd);
107 wvTrace(("name len is %d\n",afbse->cbName));
108 afbse->unused2 = getc(fd);
109 afbse->unused3 = getc(fd);
110 return(36);
111 }
112
113void wvCopyFBSE(FBSE *dest,FBSE *src)
114 {
115 memcpy(dest,src,sizeof(FBSE));
116 }
117
118
119U32 wvGetBitmap(BitmapBlip *abm,MSOFBH *amsofbh,FILE *fd)
120 {
121 U32 i,count;
122 char extra=0;
123 FILE *tmp;
124 wvTrace(("starting bitmap at %x\n",ftell(fd)));
125 for (i=0;i<16;i++)
126 abm->m_rgbUid[i] = getc(fd);
127 count=16;
128
129 abm->m_rgbUidPrimary[0] = 0;
130
131 switch (amsofbh->fbt-msofbtBlipFirst)
132 {
133 case msoblipPNG:
134 wvTrace(("msoblipPNG\n"));
135 /* sprintf(buffer,"%s-wv-%d.png",aimage,no++);*/
136 if (amsofbh->inst ^ msobiPNG)
137 extra=1;
138 break;
139 case msoblipJPEG:
140 wvTrace(("msoblipJPEG\n"));
141 /* sprintf(buffer,"%s-wv-%d.jpg",aimage,no++);*/
142 if (amsofbh->inst ^ msobiJFIF)
143 extra=1;
144 break;
145 case msoblipDIB:
146 wvTrace(("msoblipDIB\n"));
147 /* sprintf(buffer,"%s-wv-%d.dib",aimage,no++); */
148 if (amsofbh->inst ^ msobiDIB)
149 extra=1;
150 break;
151 }
152
153 if (extra)
154 {
155 for (i=0;i<16;i++)
156 abm->m_rgbUidPrimary[i] = getc(fd);
157 count+=16;
158 }
159
160 abm->m_bTag = getc(fd);
161 count++;
162 abm->m_pvBits=NULL;
163 tmp = tmpfile();
164 for (i=count;i<amsofbh->cbLength;i++)
165 fputc(getc(fd),tmp);
166 rewind(tmp);
167 abm->m_pvBits=(void *)tmp;
168 count+=i;
169 return(count);
170 }
171
172void wvCopyBitmap(BitmapBlip *dest,BitmapBlip *src)
173 {
174 U8 i;
175 for (i=0;i<16;i++)
176 {
177 dest->m_rgbUid[i] = src->m_rgbUid[i];
178 dest->m_rgbUidPrimary[i] = src->m_rgbUidPrimary[i];
179 }
180
181 dest->m_bTag = src->m_bTag;
182 dest->m_pvBits = src->m_pvBits;
183 }
184
185
186U32 wvGetMetafile(MetaFileBlip *amf,MSOFBH *amsofbh,FILE *fd)
187 {
188 char extra=0;
189 U32 i,count;
190 FILE *tmp;
191 U8 decompressf=0;
192
193 for (i=0;i<16;i++)
194 amf->m_rgbUid[i] = getc(fd);
195 count=16;
196
197 amf->m_rgbUidPrimary[0] = 0;
198
199 switch (amsofbh->fbt-msofbtBlipFirst)
200 {
201 case msoblipEMF:
202 wvTrace(("msoblipEMF\n"));
203 /*
204 sprintf(buffer,"%s-wv-%d.emf",aimage,no++);
205 */
206 if (amsofbh->inst ^ msobiEMF)
207 extra=1;
208 break;
209 case msoblipWMF:
210 wvTrace(("msoblipWMF\n"));
211 /*
212 sprintf(buffer,"%s-wv-%d.wmf",aimage,no++);
213 */
214 if (amsofbh->inst ^ msobiWMF)
215 extra=1;
216 break;
217 case msoblipPICT:
218 wvTrace(("msoblipPICT\n"));
219 /*
220 sprintf(buffer,"%s-wv-%d.pict",aimage,no++);
221 */
222 if (amsofbh->inst ^ msobiPICT)
223 extra=1;
224 break;
225 }
226
227 if (extra)
228 {
229 for (i=0;i<16;i++)
230 amf->m_rgbUidPrimary[i] = getc(fd);
231 count+=16;
232 }
233
234
235 amf->m_cb = read_32ubit(fd);
236 amf->m_rcBounds.bottom = read_32ubit(fd);
237 amf->m_rcBounds.top = read_32ubit(fd);
238 amf->m_rcBounds.right = read_32ubit(fd);
239 amf->m_rcBounds.left = read_32ubit(fd);
240 amf->m_ptSize.y = read_32ubit(fd);
241 amf->m_ptSize.x = read_32ubit(fd);
242 amf->m_cbSave = read_32ubit(fd);
243 amf->m_fCompression = getc(fd);
244 amf->m_fFilter = getc(fd);
245 amf->m_pvBits=NULL;
246 count +=34;
247
248
249 if (amf->m_fCompression == msocompressionDeflate)
250 decompressf = setdecom();
251
252 tmp = tmpfile();
253
254 for (i=count;i<amsofbh->cbLength;i++)
255 fputc(getc(fd),tmp);
256 count+=i;
257
258 if (decompressf)
259 {
260 /*
261 FILE *final = fopen("/tmp/test.wmf","w+b");
262 */
263 FILE *final = tmpfile();
264 rewind(tmp);
265 decompress(tmp,final,amf->m_cbSave,amf->m_cb);
266 fclose(tmp);
267 tmp = final;
268 rewind(tmp);
269 }
270#if 0
271
272 if (((decompressf) && (amf->m_fCompression == msocompressionDeflate)) || (amf->m_fCompression == msocompressionNone))
273 if (amsofbh->fbt-msofbtBlipFirst == msoblipWMF) /*wmf only for now*/
274 {
275 wvTrace(("converting wmf, final length should be %d, name %s\n",amf-
276 convertwmf(buffer);
277 wvTrace(("converted wmf\n"));
278 }
279
280#endif
281 rewind(tmp);
282 amf->m_pvBits=(void *)tmp;
283 return(count);
284 }
285
286
287void wvCopyMetafile(MetaFileBlip *dest,MetaFileBlip *src)
288 {
289 U8 i;
290 for (i=0;i<16;i++)
291 {
292 dest->m_rgbUid[i] = src->m_rgbUid[i];
293 dest->m_rgbUidPrimary[i] = src->m_rgbUidPrimary[i];
294 }
295 dest->m_cb = src->m_cb;
296 dest->m_rcBounds.bottom = src->m_rcBounds.bottom;
297 dest->m_rcBounds.top = src->m_rcBounds.top;
298 dest->m_rcBounds.right = src->m_rcBounds.right;
299 dest->m_rcBounds.left = src->m_rcBounds.left;
300 dest->m_ptSize.y = src->m_ptSize.y;
301 dest->m_ptSize.x = src->m_ptSize.x;
302 dest->m_cbSave = src->m_cbSave;
303 dest->m_fCompression = src->m_fCompression;
304 dest->m_fFilter = src->m_fFilter;
305 dest->m_pvBits=src->m_pvBits;
306 }
Note: See TracBrowser for help on using the repository browser.