source: trunk/gsdl/packages/wv-0.5.44-gs/src/blip.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: 11.8 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <ctype.h>
4#include <string.h>
5#include <errno.h>
6#include "wv.h"
7
8extern FILE *outputfile;
9extern FILE *erroroutput;
10extern char *outputfilename;
11
12int external_knowledge_0x01 = 0;/*when we magically know that we will not
13 be using a delay stream, i.e. big gobs of
14 emperical evidence, left external so that
15 if im wrong it'll be looking me in the face
16 */
17
18char failsafe[1];
19
20U16 idlist[NOOFIDS] = {0,0x216,0x3D4,0x542,0x6E0,0x46A,0x7A8,0x800};
21
22int wvQueryDelayStream(FBSE *afbse)
23 {
24 if ((afbse->btWin32 == msoblipERROR) && (afbse->btMacOS == msoblipERROR))
25 return(0);
26 if (external_knowledge_0x01)
27 return(0);
28 if (afbse->foDelay == 0xffffffff)
29 return(1);
30 return(1);
31 }
32
33#if 0
34char *wvGetBitmap(BitmapBlip *abm,MSOFBH *amsofbh,FBSE *afbse,FILE *infd)
35 {
36 return("/tmp/rubbish");
37 char *aimage;
38 char *buffer=NULL;
39 int count=0,extra=0;
40 U32 i;
41 static int no;
42 FILE *out;
43 for (i=0;i<16;i++)
44 abm->m_rgbUid[i] = getc(infd);
45
46 buffer = (char *)malloc(4096);
47 count+=i;
48 abm->m_rgbUidPrimary[0] = 0;
49
50 aimage = get_image_prefix();
51 switch (amsofbh->fbt-msofbtBlipFirst)
52 {
53 case msoblipPNG:
54 sprintf(buffer,"%s-wv-%d.png",aimage,no++);
55 if (amsofbh->inst ^ msobiPNG)
56 extra=1;
57 break;
58 case msoblipJPEG:
59 sprintf(buffer,"%s-wv-%d.jpg",aimage,no++);
60 if (amsofbh->inst ^ msobiJFIF)
61 extra=1;
62 break;
63 case msoblipDIB:
64 sprintf(buffer,"%s-wv-%d.dib",aimage,no++);
65 if (amsofbh->inst ^ msobiDIB)
66 extra=1;
67 break;
68 }
69
70 if (extra)
71 {
72 for (i=0;i<16;i++)
73 abm->m_rgbUidPrimary[i] = getc(infd);
74 count+=i;
75 }
76
77 abm->m_bTag = getc(infd);
78 count++;
79 abm->m_pvBits=NULL;
80 out = fopen(buffer,"wb");
81 for (i=count;i<amsofbh->cbLength;i++)
82 fputc(getc(infd),out);
83 fclose(out);
84 free(aimage);
85 return(buffer);
86 }
87#endif
88
89#if 0
90char *wvGetMetafile(MetaFileBlip *amf,MSOFBH *amsofbh,FILE *infd)
91 {
92 return("/tmp/rubbish");
93#if 0
94 char *aimage;
95 int extra=0;
96 U32 i;
97 static int no;
98 char *buffer;
99 char *tbuffer;
100 FILE *out;
101 U8 decompressf=0;
102 int count=0;
103 for (i=0;i<16;i++)
104 amf->m_rgbUid[i] = getc(infd);
105 count+=16;
106
107 amf->m_rgbUidPrimary[0] = 0;
108
109 aimage = get_image_prefix();
110 buffer = (char *)malloc(4096);
111 switch (amsofbh->fbt-msofbtBlipFirst)
112 {
113 case msoblipEMF:
114 sprintf(buffer,"%s-wv-%d.emf",aimage,no++);
115 if (amsofbh->inst ^ msobiEMF)
116 extra=1;
117 break;
118 case msoblipWMF:
119 sprintf(buffer,"%s-wv-%d.wmf",aimage,no++);
120 if (amsofbh->inst ^ msobiWMF)
121 extra=1;
122 break;
123 case msoblipPICT:
124 sprintf(buffer,"%s-wv-%d.pict",aimage,no++);
125 if (amsofbh->inst ^ msobiPICT)
126 extra=1;
127 break;
128 }
129
130 if (extra)
131 {
132 for (i=0;i<16;i++)
133 amf->m_rgbUidPrimary[i] = getc(infd);
134 count+=i;
135 }
136
137
138 amf->m_cb = read_32ubit(infd);
139 amf->m_rcBounds.bottom = read_32ubit(infd);
140 amf->m_rcBounds.top = read_32ubit(infd);
141 amf->m_rcBounds.right = read_32ubit(infd);
142 amf->m_rcBounds.left = read_32ubit(infd);
143 amf->m_ptSize.y = read_32ubit(infd);
144 amf->m_ptSize.x = read_32ubit(infd);
145 amf->m_cbSave = read_32ubit(infd);
146 amf->m_fCompression = getc(infd);
147 amf->m_fFilter = getc(infd);
148 amf->m_pvBits=NULL;
149 count +=50;
150
151
152 if (amf->m_fCompression == msocompressionDeflate)
153 {
154 decompressf = setdecom();
155 if (!(decompressf))
156 wvStrcat(buffer,".lzed");
157 }
158 else
159 wvStrcat(buffer,".lzed");
160
161 if (decompressf)
162 {
163 /*tbuffer = "/tmp/wvscratch";*/
164 tbuffer = tmpnam(NULL);
165 }
166 else
167 tbuffer = buffer;
168
169 out = fopen(tbuffer,"w+b");
170 for (i=count;i<amsofbh->cbLength;i++)
171 fputc(getc(infd),out);
172
173 if (decompressf)
174 {
175 fflush(out);
176 rewind(out);
177 decompress(out,buffer,amf->m_cbSave,amf->m_cb);
178 }
179
180 fclose(out);
181
182 if (((decompressf) && (amf->m_fCompression == msocompressionDeflate)) || (amf->m_fCompression == msocompressionNone))
183 if (amsofbh->fbt-msofbtBlipFirst == msoblipWMF) /*wmf only for now*/
184 {
185 wvTrace(("converting wmf, final length should be %d, name %s\n",amf->m_cb,buffer));
186 convertwmf(buffer);
187 wvTrace(("converted wmf\n"));
188 }
189
190 if (decompressf)
191 unlink(tbuffer);
192 free(aimage);
193 return(buffer);
194#endif
195 }
196#endif
197
198U32 twvGetFOPTE(FOPTE *afopte,FILE *infd)
199 {
200 U32 ret=0;
201 U16 dtemp;
202 dtemp = read_16ubit(infd);
203#ifdef PURIFY
204 afopte->pid = 0;
205 afopte->fBid = 0;
206 afopte->fComplex = 0;
207#endif
208 afopte->pid = (dtemp & 0x3fff);
209 afopte->fBid = ((dtemp & 0x4000)>>14);
210 afopte->fComplex = ((dtemp & 0x8000)>>15);
211 afopte->op = read_32ubit(infd);
212
213 if ( afopte->fComplex )
214 {
215 wvTrace(("1 complex len is %d (%x)\n",afopte->op,afopte->op));
216 ret = afopte->op;
217 }
218#if 0
219 else if (afopte->fBid)
220 wvTrace(("great including graphic number %d %d\n",afopte->op,afopte->op));
221#endif
222 wvTrace(("orig %x,pid is %x, val is %x\n",dtemp,afopte->pid,afopte->op));
223 return(ret);
224 }
225
226#if 0
227fsp_list *wvParseEscher(fbse_list **pic_list,U32 fcDggInfo,U32 lcbDggInfo,FILE *tablefd,FILE *mainfd)
228 {
229 int remainder;
230 U32 i,j;
231 MSOFBH amsofbh;
232 MSOFBH rmsofbh;
233 FDGG afdgg;
234 FIDCL *afidcl;
235 FBSE afbse;
236 MetaFileBlip amf;
237
238 fsp_list *afsp_list=NULL;
239 fsp_list *pfsp_list=NULL;
240 fopte_list *pfopte_list=NULL;
241 fbse_list *afbse_list=NULL;
242 fbse_list *pfbse_list=NULL;
243 FDG afdg;
244 FILE *temp=NULL;
245 /*
246 FILE *out = fopen("drawingtest","w+b");
247 */
248 FILE *out = tmpfile();
249 long finish,k=0;
250 int pid;
251 char *name;
252 long lastpos = ftell(mainfd);
253 char dodgyhack=1;
254 U32 dtest;
255
256 fseek(tablefd,fcDggInfo,SEEK_SET);
257
258 for (i=0;i<lcbDggInfo;i++)
259 fputc(fgetc(tablefd),out);
260
261 fseek(out,0,SEEK_SET);
262
263 /* must begin with msofbtDggContainer*/
264 wvGetMSOFBH(&rmsofbh,out);
265 wvTrace(("the id here is %x, loc %x, ends at %x\n",rmsofbh.fbt,ftell(out),ftell(out)+rmsofbh.cbLength));
266 if (rmsofbh.fbt != msofbtDggContainer)
267 {
268 wvTrace(("possible problem %x\n",rmsofbh.fbt));
269 dodgyhack=0;
270 }
271
272 while( (U32)(ftell(out)) < lcbDggInfo )
273 {
274 if ((dodgyhack) && ((U32)(ftell(out)) == rmsofbh.cbLength+8))
275 {
276 wvTrace(("come to the end of the root wrapper\n"));
277 wvTrace(("magin no is (%x)\n",getc(out)));
278 }
279
280
281 wvGetMSOFBH(&amsofbh,out);
282 wvTrace(("the id here is %x, loc %x, ends at %x\n",amsofbh.fbt,ftell(out),ftell(out)+amsofbh.cbLength));
283 switch(amsofbh.fbt)
284 {
285 case msofbtDgg:
286 wvGetFDGG(&afdgg,out);
287 afidcl = (FIDCL *)malloc(sizeof(FIDCL) * afdgg.cdgSaved);
288 wvTrace(("no of FIDCL is %d\n",afdgg.cdgSaved));
289 j=16;
290 for(i=0;i<afdgg.cdgSaved;i++)
291 {
292 wvGetFIDCL(&(afidcl[i]),out);
293 j+=8;
294 }
295 for(;j<amsofbh.cbLength;j++)
296 getc(out);
297 free(afidcl);
298 break;
299 case msofbtBSE:
300 finish = ftell(out)+amsofbh.cbLength;
301 if (afbse_list == NULL)
302 {
303 afbse_list = (fbse_list *)malloc(sizeof(fbse_list));
304 pfbse_list = afbse_list;
305 }
306 else
307 {
308 pfbse_list->next = (fbse_list *)malloc(sizeof(fbse_list));
309 pfbse_list = pfbse_list->next;
310 }
311 pfbse_list->next = NULL;
312 pfbse_list->filename[0] = '\0';
313
314 twvGetFBSE(&(pfbse_list->afbse),out);
315
316
317 if (pfbse_list->afbse.cbName != 0)
318 while(read_16ubit(out) != 0)
319 wvTrace(("blip name char\n"));
320 wvTrace(("the offset is %x\n",pfbse_list->afbse.foDelay));
321
322 if (wvQueryDelayStream(&(pfbse_list->afbse)))
323 {
324 if (pfbse_list->afbse.foDelay == 0xffffffff)
325 {
326 wvTrace(("invalid blip aborting\n"));
327 break;
328 }
329 temp = out;
330 out = mainfd;
331 if (pfbse_list->afbse.cRef)
332 {
333 wvTrace(("looking in mainfd\n"));
334 fseek(out,0,SEEK_END);
335 dtest = (U32)ftell(out);
336 if (pfbse_list->afbse.foDelay < dtest)
337 {
338 fseek(out,pfbse_list->afbse.foDelay,SEEK_SET);
339 dtest = 0;
340 }
341 else
342 dtest = 1;
343 }
344 else
345 dtest = 1;
346 }
347 else if (!(pfbse_list->afbse.cRef))
348 dtest = 1;
349 else
350 dtest = 0;
351
352 if (dtest == 1)
353 wvTrace(("bad offset for blip\n"));
354 else
355 {
356 wvGetMSOFBH(&amsofbh,out);
357 name = NULL;
358 switch(amsofbh.fbt-msofbtBlipFirst)
359 {
360 case msoblipWMF:
361 case msoblipEMF:
362 case msoblipPICT:
363 /*
364 name = wvGetMetafile(&amf,&amsofbh,out);
365 */
366 break;
367 case msoblipJPEG:
368 case msoblipPNG:
369 case msoblipDIB:
370 /*
371 name = wvGetBitmap(&abm,&amsofbh,&afbse,out);
372 */
373 break;
374 default:
375 for(i=0;i<amsofbh.cbLength;i++)
376 getc(out);
377 break;
378 }
379
380 if (name != NULL)
381 {
382 strcpy(pfbse_list->filename,name);
383 free(name);
384 }
385 }
386
387 if (wvQueryDelayStream(&(pfbse_list->afbse)))
388 out = temp;
389
390 /*sync the file*/
391 if (ftell(out) != finish)
392 {
393 wvTrace(("file is out of sync, pos is %x ended at %x\n",ftell(out),finish));
394 for(j=ftell(out);k<finish;k++)
395 getc(out);
396 }
397 break;
398 case msofbtSp:
399 if (afsp_list == NULL)
400 {
401 afsp_list = (fsp_list *)malloc(sizeof(fsp_list));
402 pfsp_list = afsp_list;
403 pfsp_list->next = NULL;
404 }
405 else
406 {
407 pfsp_list->next = (fsp_list *)malloc(sizeof(fsp_list));
408 pfsp_list = pfsp_list->next;
409 pfsp_list->next = NULL;
410 }
411 wvGetFSP(&(pfsp_list->afsp),out);
412 pfsp_list->afopte_list=NULL;
413 wvTrace(("yes, spid id no %x was found\n",pfsp_list->afsp.spid));
414 break;
415 case msofbtDg:
416 wvGetFDG(&afdg,out);
417 break;
418 case msofbtOPT:
419 remainder = amsofbh.cbLength;
420 pid = 0;
421 i=0;
422 /*
423 while (pid != 0x1ff)
424 */
425 while (remainder >= 6)
426 {
427 if (i==0)
428 {
429 if (pfsp_list == NULL)
430 {
431 wvTrace(("must be a top level property list\n"));
432 pfsp_list = (fsp_list *)malloc(sizeof(fsp_list));
433 }
434 pfsp_list->afopte_list = (fopte_list *)malloc(sizeof(fopte_list));
435 pfopte_list = pfsp_list->afopte_list;
436 }
437 else
438 {
439 pfopte_list->next =(fopte_list *) malloc(sizeof(fopte_list));
440 pfopte_list = pfopte_list->next;
441 }
442 pfopte_list->next = NULL;
443 remainder -= twvGetFOPTE(&(pfopte_list->afopte),out);
444 remainder -=6;
445 i+=6;
446 pid = pfopte_list->afopte.pid;
447 if (i+6>amsofbh.cbLength) /*eat the leftover*/
448 break;
449 }
450 for(;i<amsofbh.cbLength;i++)
451 getc(out);
452 break;
453 default:
454 wvTrace(("the ver was %x\n",amsofbh.ver));
455 if (amsofbh.ver != 0xf)
456 for(i=0;i<amsofbh.cbLength;i++)
457 getc(out);
458 break;
459 }
460 }
461
462
463 fclose(out);
464
465 pfbse_list = afbse_list;
466 i=0;
467 while (pfbse_list != NULL)
468 {
469 wvTrace(("graphic name is %s, bse no is %d\n",pfbse_list->filename,++i));
470 pfbse_list = pfbse_list->next;
471 }
472 *pic_list = afbse_list;
473 fseek(mainfd,lastpos,SEEK_SET);
474 return(afsp_list);
475 }
476#endif
477
478fbse_list *wvGetSPID(U32 spid,fsp_list *afsp_list,fbse_list *afbse_list)
479 {
480 fopte_list *temp;
481 U32 i;
482
483 while (afsp_list != NULL)
484 {
485 if (afsp_list->afsp.spid == spid)
486 {
487 wvTrace(("found the correct spid\n"));
488 temp = afsp_list->afopte_list;
489 while (temp != NULL)
490 {
491 if ((temp->afopte.fBid) && (!(temp->afopte.fComplex)))
492 {
493 wvTrace(("found a graphic to go with the spid, no %d\n",temp->afopte.op));
494 for (i=1;i<temp->afopte.op;i++)
495 afbse_list = afbse_list->next;
496 return(afbse_list);
497 break;
498 }
499 temp = temp->next;
500 }
501 break;
502 }
503 afsp_list = afsp_list->next;
504 }
505
506 return(NULL);
507 }
508
509
510U32 wvGetSPIDfromCP(U32 cp,textportions *portions)
511 {
512 U32 i;
513 for (i=0;i<portions->noofficedraw;i++)
514 if (cp == portions->officedrawcps[i])
515 return(portions->fspas[i].spid);
516 return(0xffffffffL);
517 }
518
519void wvGetBITMAP(BITMAP *bmp,FILE *infd)
520 {
521 int i;
522 for (i=0;i<14;i++)
523 bmp->bm[i] = getc(infd);
524 }
525
526void wvGetrc(rc *arc,FILE *infd)
527 {
528 int i;
529 for (i=0;i<14;i++)
530 arc->bm[i] = getc(infd);
531 }
532
533
534U32 twvGetFBSE(FBSE *afbse,FILE *infd)
535 {
536 int i;
537 afbse->btWin32 = getc(infd);
538 afbse->btMacOS = getc(infd);
539 for (i=0;i<16;i++)
540 afbse->rgbUid[i] = getc(infd);
541 afbse->tag = read_16ubit(infd);
542 afbse->size = read_32ubit(infd);
543 afbse->cRef = read_32ubit(infd);
544 afbse->foDelay = read_32ubit(infd);
545 afbse->usage = getc(infd);
546 afbse->cbName = getc(infd);
547 afbse->unused2 = getc(infd);
548 afbse->unused3 = getc(infd);
549 return(36);
550 }
551
Note: See TracBrowser for help on using the repository browser.