Ejemplo n.º 1
0
Archivo: table.c Proyecto: 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]));
}
Ejemplo n.º 2
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;
    }
}