U32 wvGetBlip (Blip * blip, wvStream * fd, wvStream * delay) { U32 i, count, count2; MSOFBH amsofbh; long pos = 0; count = wvGetFBSE (&blip->fbse, fd); wvTrace (("count is %d\n", count)); if (blip->fbse.cbName == 0) blip->name = NULL; else blip->name = (U16 *) wvMalloc (sizeof (U16) * blip->fbse.cbName); for (i = 0; i < blip->fbse.cbName; i++) blip->name[i] = read_16ubit (fd); count += blip->fbse.cbName * 2; wvTrace (("count is %d\n", count)); wvTrace (("offset %x\n", blip->fbse.foDelay)); if (delay) { pos = wvStream_tell (delay); if(blip->fbse.foDelay!=-1) wvStream_goto (delay, blip->fbse.foDelay); wvTrace (("offset %x\n", blip->fbse.foDelay)); fd = delay; } count2 = wvGetMSOFBH (&amsofbh, fd); wvTrace (("count is %d\n", count2)); wvTrace ( ("HERE is %x %x (%d)\n", wvStream_tell (fd), amsofbh.fbt, amsofbh.fbt - msofbtBlipFirst)); wvTrace (("type is %x\n", amsofbh.fbt)); switch (amsofbh.fbt - msofbtBlipFirst) { case msoblipWMF: case msoblipEMF: case msoblipPICT: count2 += wvGetMetafile (&blip->blip.metafile, &amsofbh, fd); break; case msoblipJPEG: case msoblipPNG: case msoblipDIB: count2 += wvGetBitmap (&blip->blip.bitmap, &amsofbh, fd); break; } wvTrace (("count is %d\n", count2)); blip->type = amsofbh.fbt - msofbtBlipFirst; if (delay) { wvStream_goto (delay, pos); return (count); } return (count + count2); }
/* Character properties * -basically just like PAPX FKPs above * however, rather than an array of BX structs in rgbx, * there is an array of bytes (giving the word offset to the CHPX) in rgb * -JB */ void wvGetCHPX_FKP (wvVersion ver, CHPX_FKP * fkp, U32 pn, wvStream * fd) { int i; U8 page[WV_PAGESIZE]; U16 pos = 0; /*size_t bytes_read; */ /* [email protected] */ /* there seem to be a lot of repeat calls... */ /* pn=0 is safe because thats the index block, not a CHPX_FKP */ if (pn != 0 && pn == wvCHPX_pn_previous) { memcpy (fkp, &wvCHPX_FKP_previous, sizeof (CHPX_FKP)); return; } wvStream_goto (fd, pn * WV_PAGESIZE); /*bytes_read= */ wvStream_read (page, WV_PAGESIZE, 1, fd); fkp->crun = (U8) page[WV_PAGESIZE - 1]; wvTrace (("chpx fkp gone to %x\n", pn * WV_PAGESIZE + (WV_PAGESIZE - 1))); wvTrace (("crun is %d\n", fkp->crun)); fkp->rgfc = (U32 *) wvMalloc (sizeof (U32) * (fkp->crun + 1)); fkp->rgb = (U8 *) wvMalloc (sizeof (U8) * (fkp->crun)); fkp->grpchpx = (CHPX *) wvMalloc (sizeof (CHPX) * (fkp->crun)); wvStream_goto (fd, pn * WV_PAGESIZE); wvTrace (("offset is %x\n", pn * WV_PAGESIZE)); for (i = 0; i < fkp->crun + 1; i++) { fkp->rgfc[i] = bread_32ubit (&(page[pos]), &pos); wvTrace (("rgfc is %x\n", fkp->rgfc[i])); } for (i = 0; i < fkp->crun; i++) fkp->rgb[i] = bread_8ubit (&(page[pos]), &pos); for (i = 0; i < fkp->crun; i++) { if (fkp->rgb[i] == 0) { wvTrace (("i is %d, using clear chpx\n", i)); wvInitCHPX (&(fkp->grpchpx[i])); } else { wvTrace ( ("chpx index i is %d, offset is %x\n", i, (pn * WV_PAGESIZE) + (fkp->rgb[i] * 2))); pos = fkp->rgb[i] * 2; wvGetCHPX (ver, &(fkp->grpchpx[i]), page, &pos); } } if (wvCHPX_pn_previous != 0) internal_wvReleaseCHPX_FKP (&wvCHPX_FKP_previous); memcpy (&wvCHPX_FKP_previous, fkp, sizeof (CHPX_FKP)); wvCHPX_pn_previous = pn; }
/* this function retrieves a generic PLCF; this is useful since it means we do not have to add specific functions for retrieving various simple PLCFs (for instance the PLCFs that store information about footnotes, endnotes and annotations are just simple arrays of U32s) plcf - a pointer to a pointer where we should allocate the structure the caller needs to free these using wvFree() once not needed offset - an offset in the stream fd where the PLCF starts len - a length in bytes (!!!) of the PLCF fd - the stream from which to read the PLCF */ int wvGetPLCF (void ** plcf, U32 offset, U32 len, wvStream * fd) { U32 i, i32, i8; if (len == 0) { *plcf = NULL; } else { *plcf = wvMalloc (len); if (*plcf == NULL) { wvError (("NO MEM 1, failed to alloc %d bytes\n",len)); return (1); } wvStream_goto (fd, offset); i32 = len / 4; i8 = len % 4; for (i = 0; i < i32; i++) ((U32*)(*plcf))[i] = read_32ubit (fd); for (i = i32*4; i < i32*4 + i8; i++) ((U8*)(*plcf))[i] = read_8ubit (fd); } return (0); }
int wvGetFRD_PLCF(FRD **frd, U32 **pos, int *nofrd, U32 offset, U32 len, wvStream *fd) { int i; if (len == 0) { *frd = NULL; *pos = NULL; *nofrd = 0; } else { *nofrd = (len - 4) / 6; *pos = (U32 *)wvMalloc((*nofrd + 1) * sizeof(U32)); if (*pos == NULL) { wvError( ("NO MEM 1, failed to alloc %d bytes\n", (*nofrd + 1) * sizeof(U32))); return 1; } *frd = (FRD *)wvMalloc(*nofrd * sizeof(FRD)); if (*frd == NULL) { wvError( ("NO MEM 1, failed to alloc %d bytes\n", *nofrd * sizeof(FRD))); wvFree(pos); return 1; } wvStream_goto(fd, offset); for (i = 0; i < *nofrd + 1; i++) (*pos)[i] = read_32ubit(fd); for (i = 0; i < *nofrd; i++) wvGetFRD(&((*frd)[i]), fd); } return 0; }
int wvGetEmpty_PLCF (U32 ** cps, U32 * nocps, U32 offset, U32 len, wvStream * fd) { U32 i; if (len == 0) { *cps = NULL; *nocps = 0; } else { *nocps = len / 4; *cps = (U32 *) malloc (*nocps * sizeof (U32)); if (*cps == NULL) { wvError ( ("NO MEM 3, failed to alloc %d bytes\n", *nocps * sizeof (U32))); return (1); } wvStream_goto (fd, offset); for (i = 0; i < *nocps; i++) (*cps)[i] = read_32ubit (fd); } return (0); }
void wvGetEscher(escherstruct *item, U32 offset, U32 len, wvStream *fd, wvStream *delay) { U32 count = 0; MSOFBH amsofbh; wvStream_goto(fd, offset); wvTrace(("offset %x, len %d\n", offset, len)); wvInitEscher(item); while (count < len) { count += wvGetMSOFBH(&amsofbh, fd); wvTrace( ("count is %x,len is %x, next len is %x\n", count, len, amsofbh.cbLength)); wvTrace(("type is %x\n ", amsofbh.fbt)); switch (amsofbh.fbt) { case msofbtDggContainer: count += wvGetDggContainer(&item->dggcontainer, &amsofbh, fd, delay); break; case msofbtDgContainer: count += wvGetDgContainer(&item->dgcontainer, &amsofbh, fd); break; default: wvError(("Not a container, panic (%x)\n", amsofbh.fbt)); return; break; } } wvTrace(("offset %x, len %d (pos %x)\n", offset, len, wvStream_tell(fd))); }
void wvGetFFN_STTBF(FFN_STTBF *item, U32 offset, U32 len, wvStream *fd) { int i; wvTrace(("reading fonts...\n")); wvTrace(("seeking to %x, len %d\n", offset, len)); if (len == 0) { item->nostrings = 0; item->ffn = NULL; } else { wvStream_goto(fd, offset); item->extendedflag = read_16ubit(fd); if (item->extendedflag == 0xFFFF) item->nostrings = read_16ubit(fd); else item->nostrings = item->extendedflag; item->extradatalen = read_16ubit(fd); item->ffn = (FFN *)wvMalloc(item->nostrings * sizeof(FFN)); for (i = 0; i < item->nostrings; i++) { #ifdef DEBUG char *dbg; #endif wvGetFFN(&(item->ffn[i]), fd); #ifdef DEBUG dbg = wvWideStrToMB(item->ffn[i].xszFfn); wvTrace(("font %d: %s\n", i, dbg)); if (dbg) wvFree(dbg); #endif } } wvTrace(("done reading fonts.\n")); }
void wvGetXst(Xst **xst, U32 offset, U32 len, wvStream *fd) { U16 clen, i; U32 count = 0; Xst *authorlist; Xst *current = NULL; if ((len == 0) || (xst == NULL)) { *xst = NULL; return; } wvStream_goto(fd, offset); *xst = (Xst *)wvMalloc(sizeof(Xst)); authorlist = *xst; if (authorlist == NULL) { wvError(("not enough mem for annotation group\n")); return; } authorlist->next = NULL; authorlist->u16string = NULL; authorlist->noofstrings = 0; current = authorlist; while (count < len) { clen = read_16ubit(fd); count += 2; current->u16string = (U16 *)wvMalloc((clen + 1) * sizeof(U16)); authorlist->noofstrings++; if (current->u16string == NULL) { wvError( ("not enough mem for author string of clen %d\n", clen)); break; } for (i = 0; i < clen; i++) { current->u16string[i] = read_16ubit(fd); count += 2; } current->u16string[i] = '\0'; if (count < len) { current->next = (Xst *)wvMalloc(sizeof(Xst)); if (current->next == NULL) { wvError(("not enough mem for annotation group\n")); break; } current = current->next; current->next = NULL; current->u16string = NULL; } } }
U32 wvStream_size (wvStream * in) { U32 size; long offset = wvStream_tell(in); wvStream_offset_from_end(in,0); size = wvStream_tell(in); wvStream_goto(in,offset); return size; }
void wvGetFFN_STTBF6 (FFN_STTBF * item, U32 offset, U32 len, wvStream * fd) { U32 count = 0; int noffn = 0; wvTrace (("reading fonts 6...\n")); wvTrace (("seeking to %x, len %d\n", offset, len)); if (len == 0) { item->nostrings = 0; item->ffn = NULL; return; } wvStream_goto (fd, offset); item->extendedflag = 0; item->nostrings = 5; /* lets just set a val to start off with */ item->extradatalen = 0; item->ffn = (FFN *) wvMalloc (item->nostrings * sizeof (FFN)); if (len != read_16ubit (fd)) wvError (("FFN STTBF lens differ\n")); count += 2; while (count < len) { #ifdef DEBUG char *dbg; #endif if (noffn == item->nostrings) { /* need to extend the array just in case */ item->nostrings += 5; item->ffn = (FFN *) realloc (item->ffn, item->nostrings * sizeof (FFN)); } wvGetFFN6 (&(item->ffn[noffn]), fd); count += (item->ffn[noffn].cbFfnM1 + 1); #ifdef DEBUG dbg = wvWideStrToMB (item->ffn[noffn].xszFfn); wvTrace (("font %d: %s\n", noffn, dbg)); if (dbg) wvFree (dbg); #endif noffn++; } if (item->nostrings != noffn) item->nostrings = noffn; wvTrace (("done reading fonts 6.\n")); }
int wvGetBTE_PLCF6 (BTE ** bte, U32 ** pos, U32 * nobte, U32 offset, U32 len, wvStream * fd) { U32 i; if (len == 0) { *bte = NULL; *pos = NULL; *nobte = 0; } else { wvTrace (("offset is %x, len is %d\n", offset, len)); *nobte = (len - 4) / (cb6BTE + 4); wvTrace (("no of bte is %d at %x\n", *nobte, offset)); *pos = (U32 *) wvMalloc ((*nobte + 1) * sizeof (U32)); if (*pos == NULL) { wvError ( ("NO MEM 1, failed to alloc %d bytes\n", (*nobte + 1) * sizeof (U32))); return (1); } *bte = (BTE *) wvMalloc (*nobte * sizeof (BTE)); if (*bte == NULL) { wvError ( ("NO MEM 1, failed to alloc %d bytes\n", *nobte * sizeof (BTE))); wvFree (pos); return (1); } wvStream_goto (fd, offset); for (i = 0; i <= *nobte; i++) { (*pos)[i] = read_32ubit (fd); wvTrace (("pos is %x\n", (*pos)[i])); } for (i = 0; i < *nobte; i++) { wvInitBTE (&((*bte)[i])); (*bte)[i].pn = read_16ubit (fd); } } return (0); }
int wvGetBKD_PLCF (BKD ** bkd, U32 ** pos, U32 * nobkd, U32 offset, U32 len, wvStream * fd) { U32 i; if (len == 0) { *bkd = NULL; *pos = NULL; *nobkd = 0; } else { *nobkd = (len - 4) / (cbBKD + 4); *pos = (U32 *) wvMalloc ((*nobkd + 1) * sizeof (U32)); if (*pos == NULL) { wvError ( ("NO MEM 1, failed to alloc %d bytes\n", (*nobkd + 1) * sizeof (U32))); return (1); } *bkd = (BKD *) wvMalloc (*nobkd * sizeof (BKD)); if (*bkd == NULL) { wvError ( ("NO MEM 1, failed to alloc %d bytes\n", *nobkd * sizeof (BKD))); wvFree (pos); return (1); } wvStream_goto (fd, offset); for (i = 0; i < *nobkd + 1; i++) { (*pos)[i] = read_32ubit (fd); } for (i = 0; i < *nobkd; i++) { wvGetBKD (&((*bkd)[i]), fd); } } return (0); }
int wvGetBTE_PLCF(BTE **bte, U32 **pos, U32 *nobte, U32 offset, U32 len, wvStream *fd) { U32 i; if (len == 0) { *bte = NULL; *pos = NULL; *nobte = 0; } else { *nobte = (len - 4) / (cbBTE + 4); wvTrace(("no of bte is %d at %x\n", *nobte, offset)); *pos = (U32 *)wvMalloc((*nobte + 1) * sizeof(U32)); if (*pos == NULL) { wvError( ("NO MEM 1, failed to alloc %d bytes\n", (*nobte + 1) * sizeof(U32))); return 1; } *bte = (BTE *)wvMalloc(*nobte * sizeof(BTE)); if (*bte == NULL) { wvError( ("NO MEM 1, failed to alloc %d bytes\n", *nobte * sizeof(BTE))); wvFree(*pos); return 1; } wvStream_goto(fd, offset); for (i = 0; i <= *nobte; i++) (*pos)[i] = read_32ubit(fd); for (i = 0; i < *nobte; i++) wvGetBTE(&((*bte)[i]), fd); } return 0; }
int wvGetBKL_PLCF(BKL **bkl, U32 **pos, U32 *nobkl, U32 bkloffset, U32 bkllen, U32 bkfoffset, U32 bkflen, wvStream *fd) { BKF *bkf; U32 *posf, nobkf; U32 i, j; if ((bkllen == 0) || (bkflen == 0)) { *bkl = NULL; *pos = NULL; *nobkl = 0; } else { /* the plcbkl table contains offsets only, bkl has to be calculated from bkf */ *nobkl = (bkllen - 4) / (/*cbBKL +*/ 4); *pos = (U32 *)wvMalloc((*nobkl + 1) * sizeof(U32)); if (*pos == NULL) { wvError( ("NO MEM 1, failed to alloc %d bytes\n", (*nobkl + 1) * sizeof(U32))); return 1; } *nobkl = (*nobkl ? *nobkl : 1); *bkl = (BKL *)wvMalloc(*nobkl * sizeof(BKL)); if (*bkl == NULL) { wvError( ("NO MEM 1, failed to alloc %d bytes\n", *nobkl * sizeof(BKL))); wvFree(*pos); return 1; } wvStream_goto(fd, bkloffset); for (i = 0; i <= *nobkl; i++) (*pos)[i] = read_32ubit(fd); /* now we have to reconstruct the bkl table; we have to get the bkf records, and then search them to find one that matches the index we are processing */ if (wvGetBKF_PLCF(&bkf, &posf, &nobkf, bkfoffset, bkflen, fd)) { wvError( ("call to wvGetBKF_PLCF failed\n")); wvFree(*pos); wvFree(*bkl); return 1; } for (i = 0; i < *nobkl; i++) { for (j = 0; j < nobkf; j++) if (bkf[j].ibkl == i) break; if (j == nobkf) { wvError( ("unmatched closing bookmark\n")); wvFree(*pos); wvFree(*bkl); wvFree(bkf); wvFree(posf); return 1; } (*bkl)[i].ibkf = (U16)j; } wvFree(bkf); wvFree(posf); } return 0; }
void wvGetFIB (FIB * item, wvStream * fd) { U16 temp16; U8 temp8; item->fEncrypted = 0; wvStream_goto (fd, 0); #ifdef PURIFY wvInitFIB (item); #endif item->wIdent = read_16ubit (fd); item->nFib = read_16ubit (fd); if ((wvQuerySupported (item, NULL) == WORD2)) { wvInitFIB (item); wvStream_offset (fd, -4); wvGetFIB2 (item, fd); return; } if ((wvQuerySupported (item, NULL) == WORD5) || (wvQuerySupported (item, NULL) == WORD6) || (wvQuerySupported (item, NULL) == WORD7)) { wvInitFIB (item); wvStream_offset (fd, -4); wvGetFIB6 (item, fd); return; } item->nProduct = read_16ubit (fd); item->lid = read_16ubit (fd); wvTrace (("lid is %x\n", item->lid)); item->pnNext = (S16) read_16ubit (fd); temp16 = read_16ubit (fd); item->fDot = (temp16 & 0x0001); item->fGlsy = (temp16 & 0x0002) >> 1; item->fComplex = (temp16 & 0x0004) >> 2; item->fHasPic = (temp16 & 0x0008) >> 3; item->cQuickSaves = (temp16 & 0x00F0) >> 4; item->fEncrypted = (temp16 & 0x0100) >> 8; item->fWhichTblStm = (temp16 & 0x0200) >> 9; item->fReadOnlyRecommended = (temp16 & 0x0400) >> 10; item->fWriteReservation = (temp16 & 0x0800) >> 11; item->fExtChar = (temp16 & 0x1000) >> 12; wvTrace (("fExtChar is %d\n", item->fExtChar)); item->fLoadOverride = (temp16 & 0x2000) >> 13; item->fFarEast = (temp16 & 0x4000) >> 14; item->fCrypto = (temp16 & 0x8000) >> 15; item->nFibBack = read_16ubit (fd); item->lKey = read_32ubit (fd); item->envr = read_8ubit (fd); temp8 = read_8ubit (fd); item->fMac = (temp8 & 0x01); item->fEmptySpecial = (temp8 & 0x02) >> 1; item->fLoadOverridePage = (temp8 & 0x04) >> 2; item->fFutureSavedUndo = (temp8 & 0x08) >> 3; item->fWord97Saved = (temp8 & 0x10) >> 4; item->fSpare0 = (temp8 & 0xFE) >> 5; item->chse = read_16ubit (fd); item->chsTables = read_16ubit (fd); item->fcMin = read_32ubit (fd); item->fcMac = read_32ubit (fd); item->csw = read_16ubit (fd); item->wMagicCreated = read_16ubit (fd); item->wMagicRevised = read_16ubit (fd); item->wMagicCreatedPrivate = read_16ubit (fd); item->wMagicRevisedPrivate = read_16ubit (fd); item->pnFbpChpFirst_W6 = (S16) read_16ubit (fd); item->pnChpFirst_W6 = (S16) read_16ubit (fd); item->cpnBteChp_W6 = (S16) read_16ubit (fd); item->pnFbpPapFirst_W6 = (S16) read_16ubit (fd); item->pnPapFirst_W6 = (S16) read_16ubit (fd); item->cpnBtePap_W6 = (S16) read_16ubit (fd); item->pnFbpLvcFirst_W6 = (S16) read_16ubit (fd); item->pnLvcFirst_W6 = (S16) read_16ubit (fd); item->cpnBteLvc_W6 = (S16) read_16ubit (fd); item->lidFE = (S16) read_16ubit (fd); item->clw = read_16ubit (fd); item->cbMac = (S32) read_32ubit (fd); item->lProductCreated = read_32ubit (fd); item->lProductRevised = read_32ubit (fd); item->ccpText = read_32ubit (fd); item->ccpFtn = (S32) read_32ubit (fd); item->ccpHdr = (S32) read_32ubit (fd); item->ccpMcr = (S32) read_32ubit (fd); item->ccpAtn = (S32) read_32ubit (fd); item->ccpEdn = (S32) read_32ubit (fd); item->ccpTxbx = (S32) read_32ubit (fd); item->ccpHdrTxbx = (S32) read_32ubit (fd); item->pnFbpChpFirst = (S32) read_32ubit (fd); item->pnChpFirst = (S32) read_32ubit (fd); item->cpnBteChp = (S32) read_32ubit (fd); item->pnFbpPapFirst = (S32) read_32ubit (fd); item->pnPapFirst = (S32) read_32ubit (fd); item->cpnBtePap = (S32) read_32ubit (fd); item->pnFbpLvcFirst = (S32) read_32ubit (fd); item->pnLvcFirst = (S32) read_32ubit (fd); item->cpnBteLvc = (S32) read_32ubit (fd); item->fcIslandFirst = (S32) read_32ubit (fd); item->fcIslandLim = (S32) read_32ubit (fd); item->cfclcb = read_16ubit (fd); item->fcStshfOrig = (S32) read_32ubit (fd); item->lcbStshfOrig = read_32ubit (fd); item->fcStshf = (S32) read_32ubit (fd); item->lcbStshf = read_32ubit (fd); item->fcPlcffndRef = (S32) read_32ubit (fd); item->lcbPlcffndRef = read_32ubit (fd); item->fcPlcffndTxt = (S32) read_32ubit (fd); item->lcbPlcffndTxt = read_32ubit (fd); item->fcPlcfandRef = (S32) read_32ubit (fd); item->lcbPlcfandRef = read_32ubit (fd); item->fcPlcfandTxt = (S32) read_32ubit (fd); item->lcbPlcfandTxt = read_32ubit (fd); item->fcPlcfsed = (S32) read_32ubit (fd); item->lcbPlcfsed = read_32ubit (fd); item->fcPlcpad = (S32) read_32ubit (fd); item->lcbPlcpad = read_32ubit (fd); item->fcPlcfphe = (S32) read_32ubit (fd); item->lcbPlcfphe = read_32ubit (fd); item->fcSttbfglsy = (S32) read_32ubit (fd); item->lcbSttbfglsy = read_32ubit (fd); item->fcPlcfglsy = (S32) read_32ubit (fd); item->lcbPlcfglsy = read_32ubit (fd); item->fcPlcfhdd = (S32) read_32ubit (fd); item->lcbPlcfhdd = read_32ubit (fd); item->fcPlcfbteChpx = (S32) read_32ubit (fd); item->lcbPlcfbteChpx = read_32ubit (fd); item->fcPlcfbtePapx = (S32) read_32ubit (fd); item->lcbPlcfbtePapx = read_32ubit (fd); item->fcPlcfsea = (S32) read_32ubit (fd); item->lcbPlcfsea = read_32ubit (fd); item->fcSttbfffn = (S32) read_32ubit (fd); item->lcbSttbfffn = read_32ubit (fd); item->fcPlcffldMom = (S32) read_32ubit (fd); item->lcbPlcffldMom = read_32ubit (fd); item->fcPlcffldHdr = (S32) read_32ubit (fd); item->lcbPlcffldHdr = read_32ubit (fd); item->fcPlcffldFtn = (S32) read_32ubit (fd); item->lcbPlcffldFtn = read_32ubit (fd); item->fcPlcffldAtn = (S32) read_32ubit (fd); item->lcbPlcffldAtn = read_32ubit (fd); item->fcPlcffldMcr = (S32) read_32ubit (fd); item->lcbPlcffldMcr = read_32ubit (fd); item->fcSttbfbkmk = (S32) read_32ubit (fd); item->lcbSttbfbkmk = read_32ubit (fd); item->fcPlcfbkf = (S32) read_32ubit (fd); item->lcbPlcfbkf = read_32ubit (fd); item->fcPlcfbkl = (S32) read_32ubit (fd); item->lcbPlcfbkl = read_32ubit (fd); item->fcCmds = (S32) read_32ubit (fd); item->lcbCmds = read_32ubit (fd); item->fcPlcmcr = (S32) read_32ubit (fd); item->lcbPlcmcr = read_32ubit (fd); item->fcSttbfmcr = (S32) read_32ubit (fd); item->lcbSttbfmcr = read_32ubit (fd); item->fcPrDrvr = (S32) read_32ubit (fd); item->lcbPrDrvr = read_32ubit (fd); item->fcPrEnvPort = (S32) read_32ubit (fd); item->lcbPrEnvPort = read_32ubit (fd); item->fcPrEnvLand = (S32) read_32ubit (fd); item->lcbPrEnvLand = read_32ubit (fd); item->fcWss = (S32) read_32ubit (fd); item->lcbWss = read_32ubit (fd); item->fcDop = (S32) read_32ubit (fd); item->lcbDop = read_32ubit (fd); item->fcSttbfAssoc = (S32) read_32ubit (fd); item->lcbSttbfAssoc = read_32ubit (fd); item->fcClx = (S32) read_32ubit (fd); item->lcbClx = read_32ubit (fd); item->fcPlcfpgdFtn = (S32) read_32ubit (fd); item->lcbPlcfpgdFtn = read_32ubit (fd); item->fcAutosaveSource = (S32) read_32ubit (fd); item->lcbAutosaveSource = read_32ubit (fd); item->fcGrpXstAtnOwners = (S32) read_32ubit (fd); item->lcbGrpXstAtnOwners = read_32ubit (fd); item->fcSttbfAtnbkmk = (S32) read_32ubit (fd); item->lcbSttbfAtnbkmk = read_32ubit (fd); item->fcPlcdoaMom = (S32) read_32ubit (fd); item->lcbPlcdoaMom = read_32ubit (fd); item->fcPlcdoaHdr = (S32) read_32ubit (fd); item->lcbPlcdoaHdr = read_32ubit (fd); item->fcPlcspaMom = (S32) read_32ubit (fd); item->lcbPlcspaMom = read_32ubit (fd); item->fcPlcspaHdr = (S32) read_32ubit (fd); item->lcbPlcspaHdr = read_32ubit (fd); item->fcPlcfAtnbkf = (S32) read_32ubit (fd); item->lcbPlcfAtnbkf = read_32ubit (fd); item->fcPlcfAtnbkl = (S32) read_32ubit (fd); item->lcbPlcfAtnbkl = read_32ubit (fd); item->fcPms = (S32) read_32ubit (fd); item->lcbPms = read_32ubit (fd); item->fcFormFldSttbs = (S32) read_32ubit (fd); item->lcbFormFldSttbs = read_32ubit (fd); item->fcPlcfendRef = (S32) read_32ubit (fd); item->lcbPlcfendRef = read_32ubit (fd); item->fcPlcfendTxt = (S32) read_32ubit (fd); item->lcbPlcfendTxt = read_32ubit (fd); item->fcPlcffldEdn = (S32) read_32ubit (fd); item->lcbPlcffldEdn = read_32ubit (fd); item->fcPlcfpgdEdn = (S32) read_32ubit (fd); item->lcbPlcfpgdEdn = read_32ubit (fd); item->fcDggInfo = (S32) read_32ubit (fd); item->lcbDggInfo = read_32ubit (fd); item->fcSttbfRMark = (S32) read_32ubit (fd); item->lcbSttbfRMark = read_32ubit (fd); item->fcSttbCaption = (S32) read_32ubit (fd); item->lcbSttbCaption = read_32ubit (fd); item->fcSttbAutoCaption = (S32) read_32ubit (fd); item->lcbSttbAutoCaption = read_32ubit (fd); item->fcPlcfwkb = (S32) read_32ubit (fd); item->lcbPlcfwkb = read_32ubit (fd); item->fcPlcfspl = (S32) read_32ubit (fd); item->lcbPlcfspl = read_32ubit (fd); item->fcPlcftxbxTxt = (S32) read_32ubit (fd); item->lcbPlcftxbxTxt = read_32ubit (fd); item->fcPlcffldTxbx = (S32) read_32ubit (fd); item->lcbPlcffldTxbx = read_32ubit (fd); item->fcPlcfhdrtxbxTxt = (S32) read_32ubit (fd); item->lcbPlcfhdrtxbxTxt = read_32ubit (fd); item->fcPlcffldHdrTxbx = (S32) read_32ubit (fd); item->lcbPlcffldHdrTxbx = read_32ubit (fd); item->fcStwUser = (S32) read_32ubit (fd); item->lcbStwUser = read_32ubit (fd); item->fcSttbttmbd = (S32) read_32ubit (fd); item->cbSttbttmbd = read_32ubit (fd); item->fcUnused = (S32) read_32ubit (fd); item->lcbUnused = read_32ubit (fd); item->fcPgdMother = (S32) read_32ubit (fd); item->lcbPgdMother = read_32ubit (fd); item->fcBkdMother = (S32) read_32ubit (fd); item->lcbBkdMother = read_32ubit (fd); item->fcPgdFtn = (S32) read_32ubit (fd); item->lcbPgdFtn = read_32ubit (fd); item->fcBkdFtn = (S32) read_32ubit (fd); item->lcbBkdFtn = read_32ubit (fd); item->fcPgdEdn = (S32) read_32ubit (fd); item->lcbPgdEdn = read_32ubit (fd); item->fcBkdEdn = (S32) read_32ubit (fd); item->lcbBkdEdn = read_32ubit (fd); item->fcSttbfIntlFld = (S32) read_32ubit (fd); item->lcbSttbfIntlFld = read_32ubit (fd); item->fcRouteSlip = (S32) read_32ubit (fd); item->lcbRouteSlip = read_32ubit (fd); item->fcSttbSavedBy = (S32) read_32ubit (fd); item->lcbSttbSavedBy = read_32ubit (fd); item->fcSttbFnm = (S32) read_32ubit (fd); item->lcbSttbFnm = read_32ubit (fd); item->fcPlcfLst = (S32) read_32ubit (fd); item->lcbPlcfLst = read_32ubit (fd); item->fcPlfLfo = (S32) read_32ubit (fd); item->lcbPlfLfo = read_32ubit (fd); item->fcPlcftxbxBkd = (S32) read_32ubit (fd); item->lcbPlcftxbxBkd = read_32ubit (fd); item->fcPlcftxbxHdrBkd = (S32) read_32ubit (fd); item->lcbPlcftxbxHdrBkd = read_32ubit (fd); item->fcDocUndo = (S32) read_32ubit (fd); item->lcbDocUndo = read_32ubit (fd); item->fcRgbuse = (S32) read_32ubit (fd); item->lcbRgbuse = read_32ubit (fd); item->fcUsp = (S32) read_32ubit (fd); item->lcbUsp = read_32ubit (fd); item->fcUskf = (S32) read_32ubit (fd); item->lcbUskf = read_32ubit (fd); item->fcPlcupcRgbuse = (S32) read_32ubit (fd); item->lcbPlcupcRgbuse = read_32ubit (fd); item->fcPlcupcUsp = (S32) read_32ubit (fd); item->lcbPlcupcUsp = read_32ubit (fd); item->fcSttbGlsyStyle = (S32) read_32ubit (fd); item->lcbSttbGlsyStyle = read_32ubit (fd); item->fcPlgosl = (S32) read_32ubit (fd); item->lcbPlgosl = read_32ubit (fd); item->fcPlcocx = (S32) read_32ubit (fd); item->lcbPlcocx = read_32ubit (fd); item->fcPlcfbteLvc = (S32) read_32ubit (fd); item->lcbPlcfbteLvc = read_32ubit (fd); wvGetFILETIME (&(item->ftModified), fd); item->fcPlcflvc = (S32) read_32ubit (fd); item->lcbPlcflvc = read_32ubit (fd); item->fcPlcasumy = (S32) read_32ubit (fd); item->lcbPlcasumy = read_32ubit (fd); item->fcPlcfgram = (S32) read_32ubit (fd); item->lcbPlcfgram = read_32ubit (fd); item->fcSttbListNames = (S32) read_32ubit (fd); item->lcbSttbListNames = read_32ubit (fd); item->fcSttbfUssr = (S32) read_32ubit (fd); item->lcbSttbfUssr = read_32ubit (fd); }
static int specCharProc (wvParseStruct * ps, U16 eachchar, CHP * achp) { Blip blip; wvStream *fil; long pos; FSPA *fspa; PICF picf; FDOA *fdoa; switch (eachchar) { case 19: /* field begin */ ps->fieldstate++; ps->fieldmiddle = 0; return 0; case 20: /* field separator */ if (achp->fOle2) { wvTrace (("Field has an embedded OLE2 object\n")); } ps->fieldmiddle = 1; return 0; case 21: /* field end */ ps->fieldstate--; ps->fieldmiddle = 0; return 0; default: break; } /* TODO: properly handle fields */ if (ps->fieldstate) { if (eachchar == 0x13 || eachchar == 0x14) return 0; } /* image handling */ switch (eachchar) { case 0x01: if (achp->fOle2) { wvTrace (("embedded OLE2 component. currently unsupported")); return 0; } pos = wvStream_tell (ps->data); wvStream_goto (ps->data, achp->fcPic_fcObj_lTagObj); wvGetPICF (wvQuerySupported (&ps->fib, NULL), &picf, ps->data); fil = picf.rgb; if (wv0x01 (&blip, fil, picf.lcb - picf.cbHeader)) { handleImage (&blip, picf.dxaGoal, picf.dyaGoal); } else { wvTrace (("Dom: strange no graphic data 1\n")); } wvStream_goto (ps->data, pos); return 0; break; case 0x08: if (wvQuerySupported (&ps->fib, NULL) == WORD8) { if (ps->nooffspa > 0) { fspa = wvGetFSPAFromCP (ps->currentcp, ps->fspa, ps->fspapos, ps->nooffspa); if (!fspa) { wvError ( ("No fspa! Panic and Insanity Abounds!\n")); return 0; } if (wv0x08 (&blip, fspa->spid, ps)) { handleImage (&blip, fspa->xaRight - fspa->xaLeft, fspa->yaBottom - fspa->yaTop); } else { wvTrace (("Dom: strange no graphic data 2\n")); return 0; } } else { wvTrace (("nooffspa was <=0 -- ignoring")); } } else { wvError ( ("pre Word8 0x08 graphic -- unsupported at the moment")); fdoa = wvGetFDOAFromCP (ps->currentcp, NULL, ps->fdoapos, ps->nooffdoa); } } return 0; }
/* return value: 1 == success 0 == failure */ int wvGetPICF (wvVersion ver, PICF * apicf, wvStream * fd) { U8 temp; U32 i; U8 *buf,*p; size_t size; long pos = wvStream_tell (fd); apicf->lcb = read_32ubit (fd); apicf->cbHeader = read_16ubit (fd); wvTrace (("size of pic is %x (%d)\n", apicf->cbHeader, apicf->cbHeader)); apicf->mfp_mm = (S16) read_16ubit (fd); wvTrace (("mm type is %d\n", apicf->mfp_mm)); apicf->mfp_xExt = (S16) read_16ubit (fd); apicf->mfp_yExt = (S16) read_16ubit (fd); apicf->mfp_hMF = (S16) read_16ubit (fd); if (apicf->mfp_mm == 99) wvGetBITMAP (&(apicf->obj.bitmap), fd); else wvGetrc (&(apicf->obj.arc), fd); apicf->dxaGoal = (S16) read_16ubit (fd); apicf->dyaGoal = (S16) read_16ubit (fd); apicf->mx = read_16ubit (fd); apicf->my = read_16ubit (fd); apicf->dxaCropLeft = (S16) read_16ubit (fd); apicf->dyaCropTop = (S16) read_16ubit (fd); apicf->dxaCropRight = (S16) read_16ubit (fd); apicf->dyaCropBottom = (S16) read_16ubit (fd); temp = read_8ubit (fd); apicf->brcl = temp & 0x0F; apicf->fFrameEmpty = (temp & 0x10) >> 4; apicf->fBitmap = (temp & 0x20) >> 5; wvTrace (("bitmap is %d\n", apicf->fBitmap)); apicf->fDrawHatch = (temp & 0x40) >> 6; apicf->fError = (temp & 0x80) >> 7; apicf->bpp = read_8ubit (fd); wvGetBRC (ver, &(apicf->brcTop), fd); wvGetBRC (ver, &(apicf->brcLeft), fd); wvGetBRC (ver, &(apicf->brcBottom), fd); wvGetBRC (ver, &(apicf->brcRight), fd); apicf->dxaOrigin = (S16) read_16ubit (fd); apicf->dyaOrigin = (S16) read_16ubit (fd); if (ver == WORD8) apicf->cProps = (S16) read_16ubit (fd); else apicf->cProps = 0; pos = wvStream_tell (fd) - pos; for (i = pos; i < apicf->cbHeader; i++) read_8ubit (fd); wvTrace (("pos is finally %x\n", wvStream_tell (fd))); wvTrace (("len of data is %d\n", apicf->lcb - apicf->cbHeader)); wvTrace ( ("ends at %x\n", wvStream_tell (fd) + apicf->lcb - apicf->cbHeader)); i = 0; if (apicf->mfp_mm < 90){ MSOFBH bse_pic_amsofbh; size_t lHeaderSize; size_t lWordStructsSize; U8 *pHeader; U8 *pWordStructs; U32 len; U32 j; U8 bmp_header[40]; U32 header_len; U32 colors_used; U16 bpp; pWordStructs = pHeader = 0; wvTrace (("test\n")); len = apicf->lcb - apicf->cbHeader; /*[email protected] store*/ pos = wvStream_tell (fd); i = wvEatOldGraphicHeader (fd, len); if(i!=-1)/*Found BMP */ { wvTrace (("len is %d, header len guess is %d\n", len, i)); if (i + 2 >= len) { wvTrace (("all read ok methinks\n")); apicf->rgb = NULL; return 1; } len -= i; pos = wvStream_tell (fd); for(j=0;j< sizeof(bmp_header);j++) bmp_header[j] = read_8ubit (fd); bpp = bmp_header[14] + (bmp_header[15] << 8); if ( bpp < 9) { colors_used = bmp_header[32] + (bmp_header[33] << 8) + (bmp_header[34] << 16) + (bmp_header[35] << 24); } else { colors_used = 0; } wvStream_goto(fd,pos); header_len = 14 + 40 + 4 * colors_used; /*Get Blip Header Size*/ lHeaderSize = PutWord8BitmapHeader(apicf, 0, len + i-14, header_len); pHeader = malloc(lHeaderSize); /*Write Blip Header*/ PutWord8BitmapHeader(apicf, pHeader, len, header_len); /*Set Type of FBSE Header*/ bse_pic_amsofbh.ver = 0; bse_pic_amsofbh.inst = msobiDIB; bse_pic_amsofbh.fbt = msofbtBlipFirst + msoblipDIB;/*msoblipJPEG msoblipPNG*/ bse_pic_amsofbh.cbLength = lHeaderSize+len; }else{/*must be WMF*/ /*Get Blip Header Size*/ lHeaderSize = PutWord8MetafileHeader(apicf, 0); pHeader = malloc(lHeaderSize); /*Write Blip Header*/ PutWord8MetafileHeader(apicf, pHeader); /*Set Type of FBSE Header*/ bse_pic_amsofbh.ver = 0; bse_pic_amsofbh.inst = msobiWMF; bse_pic_amsofbh.fbt = msofbtBlipFirst + msoblipWMF; bse_pic_amsofbh.cbLength = lHeaderSize+len; i = 0; wvStream_goto(fd,pos); } lWordStructsSize = PutWord8Structs(&bse_pic_amsofbh, 0,0); pWordStructs = malloc(lWordStructsSize); PutWord8Structs(&bse_pic_amsofbh, pWordStructs, lWordStructsSize); size = lHeaderSize + lWordStructsSize + apicf->lcb - apicf->cbHeader; p = buf = malloc(size); if(!p) { free(pWordStructs); free(pHeader); return 0; } memcpy(p, pWordStructs, lWordStructsSize); p+= lWordStructsSize; memcpy(p, pHeader, lHeaderSize); p+=lHeaderSize; free(pWordStructs); free(pHeader); } else{ size = apicf->lcb - apicf->cbHeader; p = buf = malloc(size); } #if 0 for (; i < apicf->lcb - apicf->cbHeader; i++) *p++ = read_8ubit (fd); #endif U32 length = apicf->lcb - apicf->cbHeader - i; if (fd->kind == GSF_STREAM) { gsf_input_read (GSF_INPUT (fd->stream.gsf_stream), length, p); p += length; } else if (fd->kind == FILE_STREAM) { fread(p, sizeof(guint8), length, fd->stream.file_stream); p += length; } else { memorystream_read(fd->stream.memory_stream, p, length); p += length; } /* f = fopen("test.dat","wb"); fwrite(buf, 1,size, f); fclose(f); */ wvStream_memory_create(&apicf->rgb, (char*)buf, size); return 1; }
void wvGetPAPX_FKP (wvVersion ver, PAPX_FKP * fkp, U32 pn, wvStream * fd) { int i; U8 page[WV_PAGESIZE]; U16 pos = 0; /*size_t bytes_read; */ /* [email protected] */ /* there seem to be a lot of repeat calls... */ /* pn=0 is safe because thats the index block, not a PAPX_FKP */ if (pn != 0 && pn == wvPAPX_pn_previous) { memcpy (fkp, &wvPAPX_FKP_previous, sizeof (PAPX_FKP)); return; } wvTrace ( ("seeking to %x to get crun\n", pn * WV_PAGESIZE + (WV_PAGESIZE - 1))); wvStream_goto (fd, pn * WV_PAGESIZE); /*bytes_read= */ wvStream_read (page, WV_PAGESIZE, 1, fd); fkp->crun = (U8) page[WV_PAGESIZE - 1]; fkp->rgfc = (U32 *) wvMalloc (sizeof (U32) * (fkp->crun + 1)); fkp->rgbx = (BX *) wvMalloc (sizeof (BX) * (fkp->crun)); fkp->grppapx = (PAPX *) wvMalloc (sizeof (PAPX) * (fkp->crun)); for (i = 0; i < fkp->crun + 1; i++) { fkp->rgfc[i] = bread_32ubit (&(page[pos]), &pos); wvTrace (("rgfc is %x\n", fkp->rgfc[i])); } for (i = 0; i < fkp->crun; i++) { if (ver == WORD8) wvGetBX (&fkp->rgbx[i], page, &pos); else wvGetBX6 (&fkp->rgbx[i], page, &pos); } for (i = 0; i < fkp->crun; i++) { if (fkp->rgbx[i].offset == 0) { wvTrace (("i is %d, using clear papx\n", i)); wvInitPAPX (&(fkp->grppapx[i])); } else { wvTrace ( ("papx index i is %d, offset is %x\n", i, pn * WV_PAGESIZE + fkp->rgbx[i].offset * 2)); pos = fkp->rgbx[i].offset * 2; wvGetPAPX (ver, &(fkp->grppapx[i]), page, &pos); } } if (wvPAPX_pn_previous != 0) internal_wvReleasePAPX_FKP (&wvPAPX_FKP_previous); memcpy (&wvPAPX_FKP_previous, fkp, sizeof (PAPX_FKP)); wvPAPX_pn_previous = pn; }
/* get the end cp of the piece i as a cp wvGetComplexParaBounds as fc's go to the end as a cp */ void TheTest (wvParseStruct * ps, U32 piece, BTE * btePapx, U32 * posPapx, U32 para_intervals) { U32 piececount; int ichartype; U8 chartype; U32 begincp, endcp; U32 beginfc, endfc; U32 i, j, k = 0; U32 para_fcFirst, para_fcLim; PAPX_FKP para_fkp; PAP apap; int cpiece = 0; wvVersion ver = wvQuerySupported (&ps->fib, NULL); long pos = wvStream_tell (ps->mainfd); wvInitPAPX_FKP (¶_fkp); para_fcFirst = wvConvertCPToFC (ps->currentcp, &ps->clx); for (piececount = piece; piececount < ps->clx.nopcd; piececount++) { ichartype = wvGetPieceBoundsFC (&beginfc, &endfc, &ps->clx, piececount); if(ichartype==-1) break; chartype = (U8) ichartype; wvStream_goto (ps->mainfd, beginfc); wvGetPieceBoundsCP (&begincp, &endcp, &ps->clx, piececount); if (k == 0) { wvTrace ( ("cp distance is %d, cp is %d\n", ps->currentcp - begincp, ps->currentcp)); wvTrace ( ("no of pieces is %d, this one is %d\n", ps->clx.nopcd, piece)); k++; begincp = ps->currentcp; beginfc = wvConvertCPToFC (ps->currentcp, &ps->clx); } wvTrace ( ("begin and end are %d %d (%x %x)\n", begincp, endcp, beginfc, endfc)); para_fcLim = 0xffffffffL; for (i = begincp, j = beginfc; (i < endcp && i < ps->fib.ccpText); i++, j += wvIncFC (chartype)) { if ((para_fcLim == 0xffffffffL) || (para_fcLim == j)) { wvReleasePAPX_FKP (¶_fkp); wvTrace ( ("cp and fc are %x(%d) %x\n", i, i, wvConvertCPToFC (i, &ps->clx))); cpiece = wvGetComplexParaBounds (ver, ¶_fkp, ¶_fcFirst, ¶_fcLim, wvConvertCPToFC (i, &ps->clx), &ps->clx, btePapx, posPapx, para_intervals, piececount, ps->mainfd); wvTrace ( ("para begin and end is %x %x, pieceend is %x\n", para_fcFirst, para_fcLim, wvConvertCPToFC (endcp, &ps->clx))); } if (j == para_fcFirst) { wvAssembleSimplePAP (ver, &apap, para_fcLim, ¶_fkp, ps); wvAssembleComplexPAP (ver, &apap, cpiece, ps); wvTrace ( ("table ttp are %d %d\n", apap.fInTable, apap.fTtp)); } } } wvStream_goto (ps->mainfd, pos); }