Ejemplo n.º 1
0
void DFTableSetCell(DFTable *table, unsigned int row, unsigned int col, DFCell *cell)
{
    assert((row >= 0) && (row < table->rows));
    assert((col >= 0) && (col < table->cols));
    if (table->cells[row][col] != cell) {
        DFCellRelease(table->cells[row][col]);
        table->cells[row][col] = DFCellRetain(cell);
    }
}
Ejemplo n.º 2
0
static void populateTableStructure(DFTable *structure, DFNode *concrete)
{
    // Populate table
    int row = 0;
    for (DFNode *tblChild = concrete->first; tblChild != NULL; tblChild = tblChild->next) {
        if (tblChild->tag != WORD_TR)
            continue;
        DFTableSetRowElement(structure,tblChild,row);
        int col = 0;
        for (DFNode *trChild = tblChild->first; trChild != NULL; trChild = trChild->next) {
            if (trChild->tag != WORD_TC)
                continue;

            const char *gridSpan = NULL;
            const char *vMerge = NULL;

            DFNode *tcPr = DFChildWithTag(trChild,WORD_TCPR);
            if (tcPr != NULL) {
                DFNode *gridSpanNode = DFChildWithTag(tcPr,WORD_GRIDSPAN);
                DFNode *vMergeNode = DFChildWithTag(tcPr,WORD_VMERGE);

                if (gridSpanNode != NULL)
                    gridSpan = DFGetAttribute(gridSpanNode,WORD_VAL);
                if (vMergeNode != NULL) {
                    vMerge = DFGetAttribute(vMergeNode,WORD_VAL);
                    if (vMerge == NULL)
                        vMerge = "continue";
                }
            }
            int colSpan = (gridSpan != NULL) ? atoi(gridSpan) : 1;

            DFCell *cell;
            if ((vMerge != NULL) && !DFStringEquals(vMerge,"restart") && (row > 0)) {
                cell = DFCellRetain(DFTableGetCell(structure,row-1,col));
                if (cell->rowSpan < row + 1 - cell->row)
                    cell->rowSpan = row + 1 - cell->row;
            }
            else {
                cell = DFCellNew(trChild,row,col);
                cell->colSpan = colSpan;
            }

            for (int i = 0; i < colSpan; i++)
                DFTableSetCell(structure,row,col+i,cell);
            col += colSpan;
            DFCellRelease(cell);
        }
        row++;
    }
}
Ejemplo n.º 3
0
void DFTableRelease(DFTable *table)
{
    if ((table == NULL) || (--table->retainCount > 0))
        return;

    for (unsigned int r = 0; r < table->rows; r++) {
        for (unsigned int c = 0; c < table->cols; c++) {
            DFCellRelease(table->cells[r][c]);
        }
        free(table->cells[r]);
    }
    free(table->cells);
    free(table->rowElements);
    free(table->colWidths);
    free(table);
}