예제 #1
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;
}
예제 #2
0
파일: fkp.c 프로젝트: AbiWord/wv
/* 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;
}
예제 #3
0
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;
        }
    }
}
예제 #4
0
파일: support.c 프로젝트: AbiWord/wv
void
wvStream_create (wvStream ** in, wvStreamKind kind, wvInternalStream inner)
{
    wvStream_list *listEntry;
    *in = (wvStream *) wvMalloc (sizeof (wvStream));
    (*in)->kind = kind;
    (*in)->stream = inner;
    listEntry = wvMalloc (sizeof (wvStream_list));
    listEntry->stream = (*in);
    listEntry->next = streams;
    streams = listEntry;
}
예제 #5
0
파일: bte.c 프로젝트: AbiWord/wv
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);
}
예제 #6
0
파일: plcf.c 프로젝트: AbiWord/wv
/*
   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);
}
예제 #7
0
void
wvCopyBlip(Blip *dest, Blip *src) {
    int i;

    wvCopyFBSE(&dest->fbse, &src->fbse);
    dest->type = src->type;

    if (src->name) {
        dest->name = (U16 *)wvMalloc(src->fbse.cbName * sizeof(U16));
        for (i = 0; i < src->fbse.cbName; i++)
            dest->name[i] = src->name[i];
    } else
        dest->name = NULL;
    switch (dest->type) {
        case msoblipWMF:
        case msoblipEMF:
        case msoblipPICT:
            wvCopyMetafile(&dest->blip.metafile, &(src->blip.metafile));
            break;

        case msoblipJPEG:
        case msoblipPNG:
        case msoblipDIB:
            wvCopyBitmap(&dest->blip.bitmap, &(src->blip.bitmap));
            break;
    }
}
예제 #8
0
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"));
}
예제 #9
0
파일: fbse.c 프로젝트: Distrotech/wv
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);
}
예제 #10
0
파일: bkd.c 프로젝트: AbiWord/wv
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);
}
예제 #11
0
U32
wvGetClientData(ClientData *item, MSOFBH *msofbh, wvStream *fd) {
    U32 i;

    if (msofbh->cbLength) {
        item->data = (U8 *)wvMalloc(msofbh->cbLength);
        for (i = 0; i < msofbh->cbLength; i++)
            item->data[i] = read_8ubit(fd);
    } else
        item->data = NULL;
    return msofbh->cbLength;
}
예제 #12
0
파일: support.c 프로젝트: AbiWord/wv
void
wvStream_memory_create (wvStream ** in, char *buf, size_t size)
{
    wvInternalStream str;
    MemoryStream *inner = (MemoryStream *)wvMalloc(sizeof(MemoryStream));

    inner->mem = buf;
    inner->size = size;
    inner->current = 0;

    str.memory_stream = inner;
    wvStream_create (in, MEMORY_STREAM, str);
}
예제 #13
0
파일: support.c 프로젝트: AbiWord/wv
wvStream *
wvStream_TMP_create (size_t size)
{
  wvStream * stm = NULL;

  char * buf;
  
  buf = wvMalloc(size);
  
  if (buf)
    wvStream_memory_create (&stm, buf, size);

  return stm;
}
예제 #14
0
U32
wvGetSplitMenuColors(SplitMenuColors *splitmenucolors, MSOFBH *amsofbh,
                     wvStream *fd) {
    U32 i = 0;

    splitmenucolors->noofcolors = amsofbh->cbLength / 4;
    if (splitmenucolors->noofcolors) {
        splitmenucolors->colors =
            (U32 *)wvMalloc(sizeof(U32) * splitmenucolors->noofcolors);
        for (i = 0; i < splitmenucolors->noofcolors; i++)
            splitmenucolors->colors[i] = read_32ubit(fd);
    }
    return i * 4;
}
예제 #15
0
파일: ffn.c 프로젝트: clone/wv
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"));
}
예제 #16
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;
}
예제 #17
0
void
wvCopyCHPX(CHPX *dest, CHPX *src) {
    int i;

    dest->istd     = src->istd;
    dest->cbGrpprl = src->cbGrpprl;
    if (dest->cbGrpprl)
        dest->grpprl = (U8 *)wvMalloc(dest->cbGrpprl);
    else
        dest->grpprl = NULL;
    if ((dest->grpprl == NULL) || (src->grpprl == NULL))
        return;
    for (i = 0; i < dest->cbGrpprl; i++)
        dest->grpprl[i] = src->grpprl[i];
}
예제 #18
0
파일: sep.c 프로젝트: AbiWord/wv
void
wvGetSEPX (wvVersion ver, SEPX * item, wvStream * fd)
{
    U16 i;
    item->cb = read_16ubit (fd);

    if (item->cb)
	item->grpprl = (U8 *) wvMalloc (item->cb);
    else
	item->grpprl = NULL;

    for (i = 0; i < item->cb; i++)
      {
	  item->grpprl[i] = read_8ubit (fd);
	  wvTrace (("sep is %x\n", item->grpprl[i]));
      }
}
예제 #19
0
void
wvGetCHPX(wvVersion ver, CHPX *item, U8 *page, U16 *pos) {
    U8 i;

    item->cbGrpprl = bread_8ubit(&(page[*pos]), pos);
    if (item->cbGrpprl > 0) {
        item->grpprl = (U8 *)wvMalloc(item->cbGrpprl);
        memcpy(item->grpprl, &(page[*pos]), item->cbGrpprl);
    } else
        item->grpprl = NULL;

    item->istd = 0;             /* I have no idea what to set this to... --
                                                   nothing; the istd is contained in the grpprl*/

    for (i = 0; i < item->cbGrpprl; i++)
        wvTrace(("chpx byte is %x\n", item->grpprl[i]));
}
예제 #20
0
U32
wvGetDgg(Dgg *dgg, MSOFBH *amsofbh, wvStream *fd) {
    U32 count = 0;
    U32 no;
    U32 i;

    count += wvGetFDGG(&dgg->fdgg, fd);
    if (dgg->fdgg.cidcl != 0) {
        wvTrace(("There are %d bytes left\n", amsofbh->cbLength - count));
        no = (amsofbh->cbLength - count) / 8;
        if (no != dgg->fdgg.cidcl) {
            wvWarning
                ("Must be %d, not %d as specs, test algor gives %d\n", no,
                dgg->fdgg.cidcl, dgg->fdgg.cspSaved - dgg->fdgg.cidcl);
        }
        if (no) {
            dgg->fidcl = (FIDCL *)wvMalloc(sizeof(FIDCL) * no);
            for (i = 0; i < no; i++)
                count += wvGetFIDCL(&(dgg->fidcl[i]), fd);
        }
    }
    return count;
}
예제 #21
0
파일: fbse.c 프로젝트: clone/wv
U32
wvGetBitmap (BitmapBlip * abm, MSOFBH * amsofbh, wvStream * fd)
{
    U32 i, count;
    char extra = 0;
    wvStream * stm = NULL;
    wvTrace (("starting bitmap at %x\n", wvStream_tell (fd)));
    for (i = 0; i < 16; i++)
	abm->m_rgbUid[i] = read_8ubit (fd);
    count = 16;

    abm->m_rgbUidPrimary[0] = 0;

    switch (amsofbh->fbt - msofbtBlipFirst)
      {
      case msoblipPNG:
	  wvTrace (("msoblipPNG\n"));
	  /*  sprintf(buffer,"%s-wv-%d.png",aimage,no++); */
	  if (amsofbh->inst ^ msobiPNG)
	      extra = 1;
	  break;
      case msoblipJPEG:
	  wvTrace (("msoblipJPEG\n"));
	  /*  sprintf(buffer,"%s-wv-%d.jpg",aimage,no++); */
	  if (amsofbh->inst ^ msobiJFIF)
	      extra = 1;
	  break;
      case msoblipDIB:
	  wvTrace (("msoblipDIB\n"));
	  /*  sprintf(buffer,"%s-wv-%d.dib",aimage,no++); */
	  if (amsofbh->inst ^ msobiDIB)
	      extra = 1;
	  break;
      }

    if (extra)
      {
	  for (i = 0; i < 16; i++)
	      abm->m_rgbUidPrimary[i] = read_8ubit (fd);
	  count += 16;
      }

    abm->m_bTag = read_8ubit (fd);
    abm->m_pvBits = NULL;

    count++;
    stm = wvStream_TMP_create (amsofbh->cbLength);

    if (!stm) {
      abm->m_pvBits = NULL;
      return 0;
    }

    char *tmp = wvMalloc( amsofbh->cbLength - count);
    if (!tmp) {
      abm->m_pvBits = NULL;
      return 0;
    }
    wvStream_read(tmp,1,amsofbh->cbLength - count,fd);
    wvStream_write(tmp,1,amsofbh->cbLength - count,stm);
    wvFree(tmp);
    
    wvStream_rewind (stm);
    
    abm->m_pvBits = stm;

    count += i;
    return count;
}
예제 #22
0
파일: fbse.c 프로젝트: clone/wv
U32
wvGetMetafile (MetaFileBlip * amf, MSOFBH * amsofbh, wvStream * fd)
{
    char extra = 0;
    U32 i, count;
    wvStream * stm = 0;
    char *buf, *p;

    for (i = 0; i < 16; i++)
	amf->m_rgbUid[i] = read_8ubit (fd);
    count = 16;

    amf->m_rgbUidPrimary[0] = 0;

    switch (amsofbh->fbt - msofbtBlipFirst)
      {
      case msoblipEMF:
	  wvTrace (("msoblipEMF\n"));
	  /*
	     sprintf(buffer,"%s-wv-%d.emf",aimage,no++);
	   */
	  if (amsofbh->inst ^ msobiEMF)
	      extra = 1;
	  break;
      case msoblipWMF:
	  wvTrace (("msoblipWMF\n"));
	  /*
	     sprintf(buffer,"%s-wv-%d.wmf",aimage,no++);
	   */
	  if (amsofbh->inst ^ msobiWMF)
	      extra = 1;
	  break;
      case msoblipPICT:
	  wvTrace (("msoblipPICT\n"));
	  /*
	     sprintf(buffer,"%s-wv-%d.pict",aimage,no++);
	   */
	  if (amsofbh->inst ^ msobiPICT)
	      extra = 1;
	  break;
      }

    if (extra)
      {
	  for (i = 0; i < 16; i++)
	      amf->m_rgbUidPrimary[i] = read_8ubit (fd);
	  count += 16;
      }


    amf->m_cb = read_32ubit (fd);
    amf->m_rcBounds.bottom = read_32ubit (fd);
    amf->m_rcBounds.top = read_32ubit (fd);
    amf->m_rcBounds.right = read_32ubit (fd);
    amf->m_rcBounds.left = read_32ubit (fd);
    amf->m_ptSize.y = read_32ubit (fd);
    amf->m_ptSize.x = read_32ubit (fd);
    amf->m_cbSave = read_32ubit (fd);
    amf->m_fCompression = read_8ubit (fd);
    amf->m_fFilter = read_8ubit (fd);
    amf->m_pvBits = NULL;
    count += 34;

    buf = wvMalloc(amsofbh->cbLength);
    p = buf;

    for (i = count; i < amsofbh->cbLength; i++)
	*p++ = read_8ubit (fd);
    count += i;

    wvStream_memory_create (&stm, buf, amsofbh->cbLength);

    amf->m_pvBits = stm; 

    return (count);
}
예제 #23
0
void
wvUpdateCHPXBucket(UPXF *src) {
    U16 i = 0, j;
    U16 sprm;
    U8  sprm8;
    U16 len = 0;
    int temp;

    U8 *pointer, *dpointer;
    U8 *grpprl = NULL;

    i = 0;
    if (src->cbUPX == 0)
        return;
    pointer = src->upx.chpx.grpprl;
    wvTrace(("Msrc->cbUPX len is %d\n", src->cbUPX));
    for (i = 0; i < src->cbUPX; i++)
        wvTrace(("%x\n", src->upx.chpx.grpprl[i]));
    wvTrace(("Mend\n"));
    i   = 0;
    len = 0;
    while (i < src->cbUPX) {
        sprm8 = dread_8ubit(NULL, &pointer);
        wvTrace(("Mpre the sprm is %x\n", sprm8));
        sprm = (U16)wvGetrgsprmWord6(sprm8);
        wvTrace(("Mpost the sprm is %x\n", sprm));
        i++;
        len += 2;
        temp = wvEatSprm(sprm, pointer, &i);
        wvTrace(("Mlen of op is %d\n", temp));
        pointer += temp;
        wvTrace(("Mp dis is %d\n", pointer - src->upx.chpx.grpprl));
        len += temp;
    }
    wvTrace(("Mlen ends up as %d\n", len));

    if (len == 0)
        return;

    grpprl = (U8 *)wvMalloc(len);

    dpointer = grpprl;

    i       = 0;
    pointer = src->upx.chpx.grpprl;
    while (i < src->cbUPX) {
        sprm8 = dread_8ubit(NULL, &pointer);
        sprm  = (U16)wvGetrgsprmWord6(sprm8);
        i++;
        *dpointer++ = (sprm & 0x00FF);
        *dpointer++ = (sprm & 0xff00) >> 8;
        temp        = wvEatSprm(sprm, pointer, &i);
        for (j = 0; j < temp; j++)
            *dpointer++ = *pointer++;
        wvTrace(("Mlen of op is %d\n", temp));
    }
    wvFree(src->upx.chpx.grpprl);
    src->upx.chpx.grpprl = grpprl;
    src->cbUPX           = len;
    for (i = 0; i < src->cbUPX; i++)
        wvTrace(("%x\n", src->upx.chpx.grpprl[i]));
}
예제 #24
0
/*
   Paragraph List Formatting

   Given a paragraph and its corresponding PAP, the following process must be
   followed to find out the paragraph's list information:

 * Using the pap.ilfo, look up the LFO record in the pllfo with that
     (1-based) index.

 * Using the LFO, and the pap.ilvl, check to see if there are any
     overrides for this particular level. If so, and if the override
     pertains to both formatting and start-at value, use the LVL record from
     the correct LFOLVL in the LFO, and skip to step 5.

 * If the override does not pertain to either formatting or start-at
     value, we must look up the LST for this list. Using the LFO's List ID,
     search the rglst for the LST with that List ID.

 * Now, take from this LST any information (formatting or start-at value)
     we still need after consulting the LFO.

 * Once we've got the correct LVL record, apply the lvl.grpprlPapx to the
     PAP. It may adjust the indents and tab settings for the paragraph.

 * Use the other information in the LVL, such as the start at, number
     text, and grpprlChpx, to determine the appearance of the actual
     paragraph number text.
 */
int
wvGetListEntryInfo(wvVersion ver, LVL **finallvl, U32 **nos, U8 **nfcs,
                   LVL *retlvl, LFO **retlfo, PAP *apap, LFO **lfo,
                   LFOLVL *lfolvl, LVL *lvl, U32 *nolfo, LST **lst,
                   U16 *noofLST) {
    LST *alst = NULL;
    U32 i, number = 0;
    S32 j;
    U32 oldno;
    U32 fakeid;

    wvTrace(("given ilfo of %d %d\n", apap->ilfo, apap->ilvl));
    if (apap->ilfo < 0) {
        apap->ilfo = abs(apap->ilfo);
        wvWarning
            ("Insane negative ilfo value, normalizing to %d and hoping for the best\n",
            apap->ilfo);
    }

    if ((apap->ilfo == 2047) || (ver != WORD8)) {
        retlvl->lvlf.iStartAt = apap->anld.iStartAt;
        retlvl->lvlf.nfc      = apap->anld.nfc;
        wvTrace(
            ("start %d,type is %d\n", apap->anld.iStartAt,
             apap->anld.nfc));
        retlvl->lvlf.jc            = apap->anld.jc;
        retlvl->lvlf.fLegal        = 0; /*? */
        retlvl->lvlf.fNoRestart    = 0; /*? */
        retlvl->lvlf.fPrev         = apap->anld.fPrev;
        retlvl->lvlf.fPrevSpace    = apap->anld.fPrevSpace;
        retlvl->lvlf.fWord6        = 1;
        retlvl->lvlf.rgbxchNums[0] = 0; /*wrong for now */
        retlvl->lvlf.ixchFollow    = 2; /*wrong for now */
        retlvl->lvlf.dxaSpace      = apap->anld.dxaSpace;
        retlvl->lvlf.dxaIndent     = apap->anld.dxaIndent;
        retlvl->lvlf.cbGrpprlChpx  = 0;         /* wrong */
        retlvl->lvlf.cbGrpprlPapx  = 0;         /* wrong */
        retlvl->lvlf.reserved1     = 0;
        retlvl->lvlf.reserved2     = 0;
        retlvl->grpprlChpx         = NULL; /* wrong */
        retlvl->grpprlPapx         = NULL; /* wrong */



        /* wrong: begin of numbertext twiddling */
        wvTrace(("before len %d\n", apap->anld.cxchTextBefore));
        wvTrace(("after len %d\n", apap->anld.cxchTextAfter));
        retlvl->numbertext = (XCHAR *)wvMalloc(sizeof(XCHAR) * 64);
        i = 0;
        for ( ; i < apap->anld.cxchTextBefore; i++)
            retlvl->numbertext[i] = apap->anld.rgxch[i];

        retlvl->numbertext[i] = 2;

        for (i = apap->anld.cxchTextBefore; i < apap->anld.cxchTextAfter; i++)
            retlvl->numbertext[i + 1] = apap->anld.rgxch[i];

        retlvl->numbertext[i + 1] = '\0';
        /* end of numbertext twiddling */


        /* temp test */
        if (retlvl->lvlf.nfc > 5)
            retlvl->numbertext[0] = 0;


        /*word 6 anld, parse that instead */
        fakeid = wvCheckSumANLD(&apap->anld);
        wvTrace(("creating a fake id of %x\n", fakeid));
        for (i = 0; i < *nolfo; i++) {
            if (fakeid == (*lfo)[i].lsid) {
                wvTrace(
                    ("This is not the first time we've seen this list\n"));
                apap->ilfo = i + 1;

                if (apap->nLvlAnm >= 10)
                    apap->nLvlAnm -= 10;

                if ((apap->nLvlAnm == 1) || (apap->nLvlAnm == 0))
                    apap->ilvl = 0;
                else
                    apap->ilvl = apap->nLvlAnm - 1;

                if (apap->ilvl >= 10)
                    apap->ilvl -= 10;

                for (i = 0; i < 9; i++)
                    (*nos)[(apap->ilfo - 1) * 9 + i] = 0xffffffffL;
                for (i = 0; i < 9; i++)
                    (*nfcs)[(apap->ilfo - 1) * 9 + i] = 0xff;

                wvTrace(("ilvl %d\n", apap->ilvl));


                /* if this anld is a dodgy one 0x2e */
                if ((apap->ilvl) && (apap->anld.fNumber1 == 0x2e)) {
                    wvTrace(("Suspicious\n"));
                    switch (apap->ilvl) {
                        case 1:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 4;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 3;
                            break;

                        case 2:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 2;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 0;
                            break;

                        case 3:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 4;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 4;
                            break;

                        case 4:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 0;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 0;
                            break;

                        case 5:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 4;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 4;
                            break;

                        case 6:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 2;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 2;
                            break;

                        case 7:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 4;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 4;
                            break;

                        case 8:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 2;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 2;
                            break;
                    }
                }
                return 0;
            }
        }

        wvTrace(("This is the first time we've seen this list\n"));

        oldno = *nolfo;
        (*nolfo)++;

        /*
           realloc the lfo list to be one bigger,
         */
        *lfo  = (LFO *)realloc(*lfo, sizeof(LFO) * (*nolfo));
        *nos  = (U32 *)realloc(*nos, sizeof(U32) * 9 * (*nolfo));
        *nfcs = (U8 *)realloc(*nfcs, 9 * (*nolfo));
        wvTrace(("nos is now %d long\n", 9 * (*nolfo)));
        *finallvl = (LVL *)realloc(*finallvl, 9 * (*nolfo) * sizeof(LVL));

        apap->ilfo = *nolfo;

        wvTrace(("ilvl is %d, nLvlAnm is %d\n", apap->ilvl, apap->nLvlAnm));
        if (apap->nLvlAnm >= 10)
            apap->nLvlAnm -= 10;

        if ((apap->nLvlAnm == 1) || (apap->nLvlAnm == 0))
            apap->ilvl = 0;
        else
            apap->ilvl = apap->nLvlAnm - 1;

        wvTrace(("ilfo set to %d\n", apap->ilfo));

        /* begin new test */
        (*noofLST)++;
        *lst = (LST *)realloc(*lst, sizeof(LST) * (*noofLST));
        wvInitLST(&(((*lst)[(*noofLST) - 1])));
        (*lst)[(*noofLST) - 1].lstf.lsid = fakeid;
        wvTrace(("ilvl is %d\n", apap->ilvl));
        wvCopyLVL(&(((*lst)[(*noofLST) - 1]).lvl[apap->ilvl]), retlvl);
        /* end new test */
        wvTrace(("End\n"));


        wvInitLFO(&((*lfo)[apap->ilfo - 1]));
        (*lfo)[apap->ilfo - 1].lsid = fakeid;   /*how about this? */
        *retlfo = &((*lfo)[apap->ilfo - 1]);
        for (i = 0; i < 9; i++) {
            (*nos)[(apap->ilfo - 1) * 9 + i]  = 0xffffffffL;
            (*nfcs)[(apap->ilfo - 1) * 9 + i] = 0xff;
            wvInitLVL(&((*finallvl)[(apap->ilfo - 1) * 9 + i]));
            wvCopyLVL(&((*finallvl)[(apap->ilfo - 1) * 9 + i]), retlvl);
        }


        /*
           and set the ilfo and ilvl of the list to point to that fake entry instead
           and we'll have to repeat the procedure for the liststartnos
         */
        return 0;
    } else if (apap->ilfo == 0) {
        /* no number */
        return 0;
    }
    if (apap->ilfo > (S32)(*nolfo)) {
        wvWarning
            ("ilfo no %d, is greater than the number of existing lfo's (%d)\n",
            apap->ilfo, *nolfo);
        return 1;
    }

    /*
       Using the pap.ilfo, look up the LFO record in the pllfo with that
       (1-based) index. == (*lfo)[apap->ilfo]
     */

    *retlfo = &((*lfo)[apap->ilfo - 1]);

    wvTrace(("looking for id %x\n", (*retlfo)->lsid));

    if ((*lfo)[apap->ilfo - 1].clfolvl) {
        /*
           Using the LFO, and the pap.ilvl, check to see if there are any
           overrides for this particular level. If so, and if the override
           pertains to both formatting and start-at value, use the LVL record
           from the correct LFOLVL in the LFO, and skip to step 5.
         */
        wvTrace(("some overridden levels, ilfo %d\n", apap->ilfo));

        /*
           there are some levels overridden, find out if the level being overridden
           is the same as the level the paragraph wants
         */
        for (j = 0; j < apap->ilfo - 1; j++)
            number += (*lfo)[j].clfolvl;

        for (i = 0; i < (*lfo)[apap->ilfo - 1].clfolvl; i++) {
            if (lfolvl[i + number].ilvl == apap->ilvl) {
                /* the requested level is overridden */
                if ((lfolvl[i + number].fFormatting) &&
                    (lfolvl[i + number].fStartAt)) {
                    /*save the existing lvl and swap in this new one instead */
                    alst =
                        wvSearchLST((*lfo)[apap->ilfo - 1].lsid,
                                    *lst, *noofLST);

                    /*use the LVL record from the correct LFOLVL in the LFO */
                    wvCopyLVL(retlvl, &(lvl[i + number]));
                } else if (lfolvl[i + number].fStartAt) {
                    alst =
                        wvSearchLST((*lfo)[apap->ilfo - 1].lsid,
                                    *lst, *noofLST);

                    /* the lvl is the standard one with a new startat value */
                    wvCopyLVL(retlvl, &(alst->lvl[apap->ilvl]));
                    retlvl->lvlf.iStartAt = lfolvl[i + number].iStartAt;
                } else if (lfolvl[i + number].fFormatting) {
                    alst =
                        wvSearchLST((*lfo)[apap->ilfo - 1].lsid,
                                    *lst, *noofLST);

                    /* the lvl is the overridden one, with the original startat */
                    wvCopyLVL(retlvl, &(lvl[i + number]));
                    retlvl->lvlf.iStartAt =
                        alst->lvl[apap->ilvl].lvlf.iStartAt;
                }
            }
        }
    }

    if (alst == NULL) {
        /*
           if there no overridden levels i assume that we
           search for the appropiate LST
         */
        alst = wvSearchLST((*lfo)[apap->ilfo - 1].lsid, *lst, *noofLST);
        if (alst != NULL) {
            wvTrace(("ilvl is %d\n", apap->ilvl));
            if ((alst->lstf.fSimpleList) && (apap->ilvl)) {
                wvWarning
                    ("Level %d requested from list with 1 level\n",
                    apap->ilvl + 1);
                wvCopyLVL(retlvl, &(alst->lvl[0]));
            } else
                wvCopyLVL(retlvl, &(alst->lvl[apap->ilvl]));
            wvTrace(("string len is %d", retlvl->numbertext[0]));
            wvTrace(("offset is %d\n", retlvl->lvlf.rgbxchNums[0]));
        }
    }

    if (alst == NULL) {
        wvError(("No LST found for list\n"));
        return 1;
    }

    return 0;
}
예제 #25
0
파일: fkp.c 프로젝트: AbiWord/wv
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;
}
예제 #26
0
파일: table.c 프로젝트: AbiWord/wv
/*
-------------------------
|          |            |
-------------------------
|   | | |    |     |    |
-------------------------
|                       |
-------------------------
|     |         |       |
-------------------------

==>

|   | | |  | |  |  |    |

As in this example we create a list of cell begin
positions which is a superset of all begin
positions in all rows, once we have this list we
restart at the top of the table and figure out
how many spans each cell has to achieve to match
back up to its original boundaries.

We will have to match boundaries that are with in
3 units of eachother to be the same boundary as
that occurs frequently in word tables, (gagh!)
*/
void
wvSetTableInfo (wvParseStruct * ps, TAP * ptap, int no)
{
    BintreeInfo tree;
    Node *testn, *testp;
    int i, j, k;

    if (ps->vmerges)
      {
	  wvTrace (("vmerges is not NULL\n"));
	  for (i = 0; i < ps->norows; i++)
	      wvFree (ps->vmerges[i]);
	  wvFree (ps->vmerges);
	  ps->vmerges = NULL;
      }

    if (no == 0)
      {
	  wvWarning ("Broken tables, continuing and hoping for the best\n");
	  ps->nocellbounds = 0;
	  return;
      }

    InitBintree (&tree, cellCompLT, cellCompEQ);

    wvTrace (("we still ok, no is %d\n", no));

    for (i = 0; i < no; i++)
      {
		  for (j = 0; j < ptap[i].itcMac + 1; j++)
	    {
		wvTrace (("%d\n", ptap[i].rgdxaCenter[j]));
		InsertNode (&tree, (void *) &(ptap[i].rgdxaCenter[j]));
	    }
      }
    wvTrace (("end of in\n"));

    testn = NextNode (&tree, NULL);

    ps->nocellbounds = tree.no_in_tree;
    wvFree (ps->cellbounds);
    if (tree.no_in_tree)
	ps->cellbounds = (S16 *) wvMalloc (sizeof (S16) * tree.no_in_tree);
    else
	ps->cellbounds = NULL;

    i = 0;
    wvTrace (("No in tree is %d\n", tree.no_in_tree));
    while (testn != NULL)
      {
	  ps->cellbounds[i++] = *((S16 *) testn->Data);
	  wvTrace (("cellbound are %d\n", ps->cellbounds[i - 1]));
	  testp = NextNode (&tree, testn);
	  wvDeleteNode (&tree, testn);
	  testn = testp;
      }
    wvTrace (("No in tree according to i is %d\n", i));

    wvTrace (("end of out\n"));

    ps->vmerges = (S16 **) wvMalloc (sizeof (S16 *) * no);
    wvTrace (("no of rows is %d\n", no));
    for (i = 0; i < no; i++)
      {
	  ps->vmerges[i] = (S16 *) wvMalloc (sizeof (S16) * ptap[i].itcMac);
	  wvTrace (("no of cells is %d\n", ptap[i].itcMac));
	  for (j = 0; j < ptap[i].itcMac; j++)
	      ps->vmerges[i][j] = 1;
      }

    for (i = no - 1; i > 0; i--)
      {
	  for (j = 0; j < ptap[i].itcMac; j++)
	    {
		wvTrace (
			 ("Vertical merge is %d\n",
			  ptap[i].rgtc[j].fVertMerge));
		if (ptap[i].rgtc[j].fVertMerge)
		  {
		      wvTrace (
			       ("Vertical merge found, row %d, cell %d\n", i,
				j));
		      /* 
		         find a cell above me with the same boundaries
		         if it is also merged increment it, and set myself to 0
		         else leave me alone
		       */
		      for (k = 0; k < ptap[i - 1].itcMac; k++)	/* the row above */
			{
			    wvTrace (
				     ("cell begins are %d %d\n",
				      ptap[i - 1].rgdxaCenter[k],
				      ptap[i].rgdxaCenter[j]));
			    wvTrace (
				     ("cell ends are %d %d\n",
				      ptap[i - 1].rgdxaCenter[k + 1],
				      ptap[i].rgdxaCenter[j + 1]));

			    if (
				(cellCompEQ
				 ((void *) &(ptap[i - 1].rgdxaCenter[k]),
				  (void *) &(ptap[i].rgdxaCenter[j])))
				&&
				(cellCompEQ
				 ((void *) &(ptap[i - 1].rgdxaCenter[k + 1]),
				  (void *) &(ptap[i].rgdxaCenter[j + 1]))))
			      {
				  wvTrace (("found a cell above me, yippee\n"));
				  if (ptap[i - 1].rgtc[k].fVertMerge)
				    {
					ps->vmerges[i - 1][k] +=
					    ps->vmerges[i][j];
					ps->vmerges[i][j] = 0;
				    }
			      }

			}
		  }
	    }
      }


    for (i = 0; i < no; i++)
	for (j = 0; j < ptap[i].itcMac; j++)
	    wvTrace (("rowspan numbers are %d\n", ps->vmerges[i][j]));
}
예제 #27
0
U32
wvGetClientTextbox(ClientTextbox *item, MSOFBH *amsofbh, wvStream *fd) {
    item->textid  = (U32 *)wvMalloc(amsofbh->cbLength);
    *item->textid = read_32ubit(fd);
    return amsofbh->cbLength;
}
예제 #28
0
/*
   Apply the first UPX (UPX.chpx) in std.grupx to the UPE.

   To apply a UPX.chpx to a UPE.chpx, take the grpprl in UPE.chpx.grpprl (which
   has a length of UPE.chpx.cbGrpprl) and merge the grpprl in UPX.chpx.grpprl
   into it.

   Merging grpprls is a tricky business, but for character styles it is easy
   because no prls in character style grpprls should interact with each other.
   Each prl from the source (the UPX.chpx.grpprl) should be inserted into the
   destination (the UPE.chpx.grpprl) so that the sprm of each prl is in increasing
   order, and any prls that have the same sprm are replaced by the prl in the
   source.

   UPE.chpx.cbGrpprl is then set to the length of resulting grpprl, and
   UPE.chpx.istd is set to the style's istd.
 */
void
wvMergeCHPXFromBucket(CHPX *dest, UPXF *src) {
    BintreeInfo tree;
    Node        *testn, *testp;
    U16         i = 0, j;
    U16         sprm;
    U8          len = 0;
    U8          temp;
    Node        *test = NULL;

    U8 *pointer, *dpointer;
    U8 *grpprl = NULL;

    /*
       use a binary tree ala the wmf stuff and first insert every dest sprm into it,
       then insert every src sprm into it, take the full count and take them out of
       the tree and create the list from them
     */
    InitBintree(&tree, wvCompLT, wvCompEQ);
    pointer = dest->grpprl;

    while (i < dest->cbGrpprl) {
        wvTrace(("gotcha the sprm is %x\n", *((U16 *)pointer)));
        test = InsertNode(&tree, (void *)pointer);
        sprm = dread_16ubit(NULL, &pointer);
        wvTrace(("the sprm is %x\n", sprm));
        temp     = wvEatSprm(sprm, pointer, &i);
        pointer += temp;
        i       += 2;
        if (test)
            len += temp + 2;
    }

    i       = 0;
    pointer = src->upx.chpx.grpprl;
    i       = 0;
    while (i < src->cbUPX) {
        /*wvTrace(("gotcha 2 the sprm is %x\n",*((U16 *)pointer))); */
        test = InsertNode(&tree, (void *)pointer);
        sprm = dread_16ubit(NULL, &pointer);
        i   += 2;
        wvTrace(("the sprm is %x\n", sprm));
        temp = wvEatSprm(sprm, pointer, &i);
        wvTrace(("len of op is %d\n", temp));
        pointer += temp;
        wvTrace(("p dis is %d\n", pointer - src->upx.chpx.grpprl));
        if (test)
            len += temp + 2;
    }

    if (len != 0)
        grpprl = (U8 *)wvMalloc(len);
    else
        return;


    dpointer = grpprl;

    testn = NextNode(&tree, NULL);
    while (testn != NULL) {
        pointer = (U8 *)testn->Data;
        sprm    = sread_16ubit(pointer);
        wvTrace(("methinks the sprm is %x\n", sprm));
        pointer += 2;

        i = 0;
        wvEatSprm(sprm, pointer, &i);
        wvTrace(("i is now %d\n", i));

        pointer = (U8 *)testn->Data;
        for (j = 0; j < i + 2; j++)
            *dpointer++ = *pointer++;

        testp = NextNode(&tree, testn);
        wvDeleteNode(&tree, testn);
        testn = testp;
    }
    wvFree(dest->grpprl);
    dest->grpprl   = grpprl;
    dest->cbGrpprl = len;

    /*test */
    i       = 0;
    pointer = dest->grpprl;
    while (i < dest->cbGrpprl) {
        sprm = dread_16ubit(NULL, &pointer);
        wvTrace(("final test the sprm is %x\n", sprm));
        temp     = wvEatSprm(sprm, pointer, &i);
        pointer += temp;
        i       += 2;
        if (test)
            len += temp + 2;
    }
}
예제 #29
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;
}
예제 #30
0
파일: picf.c 프로젝트: gxf/heigong
U32 PutWord8Structs(MSOFBH *bse_pic_amsofbh, U8* buf, size_t size)
{
	long count;
	MSOFBH amsofbh,opt_amsofbh,bse_amsofbh;
	FBSE afbse;
	FOPTE *fopte;
	
	wvStream OutStream;
	wvStream *fd;
	U8* int_buf;
	int i;

	if(!bse_pic_amsofbh)
		 return 0;

	count = 0;

	
    if(buf){
		fd = &OutStream;
		int_buf = wvMalloc(size);
		wvStream_memory_create(&fd, (char*)int_buf, size); 
	}
	else
		fd = 0;
	/*Container Data*/
	
	/*Init Data
	*OPT amsofbh*/
	opt_amsofbh.ver=0;
	opt_amsofbh.inst=0;
	opt_amsofbh.fbt = msofbtOPT;
	opt_amsofbh.cbLength = sizeof(FOPTE);
	
	/*OPT*/
	fopte = (FOPTE *) wvMalloc (sizeof (FOPTE) * 2);
	for(i=0;i<2;i++){
	 (fopte)[i].pid=0;
	 (fopte)[i].op=1;/*-i;*/
	 (fopte)[i].fComplex=0;
	 (fopte)[i].fBid=1;/*+i*(79999);*/
	 (fopte)[i].entry=0;
	}

	/*Container amsofbh*/
	amsofbh.ver=0;
	amsofbh.inst=0;
	amsofbh.fbt = msofbtSpContainer;
	amsofbh.cbLength = sizeof(opt_amsofbh) + opt_amsofbh.cbLength;
	
	/*Write Data*/
	/*Container amsofbh*/
	count+=wvPutMSOFBH(&amsofbh, fd); 
	
	/*OPT amsofbh*/
	count+=wvPutMSOFBH(&opt_amsofbh, fd);
	
	/*OPT */
	if(buf)
		wvPutFOPTEArray(&fopte,&opt_amsofbh,fd);
	count+=opt_amsofbh.cbLength;
	wvFree(fopte);

	/*Set Blip Data */
	memset(&afbse,0,sizeof(afbse));
	afbse.btMacOS = 3;
	afbse.btWin32 = 4;
	afbse.cRef    = 1;
	afbse.tag     = 0xff;
	afbse.size = sizeof(*bse_pic_amsofbh) + bse_pic_amsofbh->cbLength;
	
	/*msofbtBSE amsofbh*/
	bse_amsofbh.ver=0;
	bse_amsofbh.inst=0;
	bse_amsofbh.fbt = msofbtBSE;
	bse_amsofbh.cbLength = sizeof(afbse) + afbse.size;

	count+=wvPutMSOFBH(&bse_amsofbh, fd);
	
	if(buf)
	 wvPutFBSE (&afbse, fd);
	count+=sizeof(afbse);
	
	count+=wvPutMSOFBH(bse_pic_amsofbh, fd);
	
	if(buf){
		memcpy(buf, int_buf, size);
	}
	return count;
}