Re: Tables: what can go in a cell (part 2)

Dave Raggett (dsr@hplb.hpl.hp.com)
Thu, 9 Feb 95 12:54:07 EST

> There will be a natural tendency to state that the end of a given table cell
> closes all tags opened within it. That is correct behavior, though the
> Puritan side of me resists making that a feature of the spec; I am leery
> of grammatical shortcuts.

The DTD specifies which for which elements you can omit the end tags.
Needless to say good clients will be able to recover gracefully from
unexpected missing end tags, but this should flag an error. Arena works
this way.

> Also, this posting doesn't address the issue of how many elements are allowed
> in a table cell or in what direction the table grows to accomodate a given
> element (or collection thereof) in a given cell.

This is old ground. By default, the parser works out the max and min width
requirements for each cell and hence each column. The columns are then
allocated to take advantage of the space budget. The code is acually more
compact than an a complete English description though ...

Cell contents are determined by the %body.content entity and as such can
contain headings, paragraphs (plain text), block elements, HR, ADDRESS,
form elements, and nested tables.

The algorithm for assigning column widths works fine with nested tables.
You simply propagate the min/max widths of the nested table to the column
containing it.

The code from Arena to assign column widths is given below. It could be
improved, e.g. to use variables for the cell margins. It was designed for
HTML+ and as such needs further work to cope with nested tables and
the HTML 3.0 colspec attribute, neither of which is expected to cause
much problems, once the data structures have been redesigned. I will be
happy to share the new code when I get it working in a few weeks time.

if (prepass) /* assign actual column widths */
{
for (i = 1, min = 3, max = 3, W = 0; i <= COLS(widths); ++i)
{
min += 7 + widths[i].min;
max += 7 + widths[i].max;
W += widths[i].max - widths[i].min;
}

/* if max fits in window then use max widths */

max_width = frame->width - right - left;

if (max <= max_width)
{
x = left + (max_width - max)/2;

for (i = 1; i <= COLS(widths); ++i)
{
widths[i].left = x + 3;
x += 7 + widths[i].max;
widths[i].right = x - 4;
}
}
else if (min < max_width) /* smart widths */
{
x = left;
spare = max_width - min;

for (i = 1; i <= COLS(widths); ++i)
{
w = widths[i].max - widths[i].min;
widths[i].left = x + 3;
x += 7 + widths[i].min + (spare * w)/W;
widths[i].right = x - 4;
}
}
else /* assign minimum column widths */
{
x = left;

for (i = 1; i <= COLS(widths); ++i)
{
widths[i].left = x + 3;
x += 7 + widths[i].min;
widths[i].right = x - 4;
}
}

/* and do second pass to draw table */

bufptr = table_bufptr;
PixOffset = table_offset;
prepass = 0;
ProcessTableForm(2);
goto draw_table;
}

Free(widths); /* free column widths */
Here = left;
PixOffset += LineSpacing[IDX_H1FONT]/2;
}

-- Dave Raggett <dsr@w3.org> tel: +44 117 922 8046 fax: +44 117 922 8924
Hewlett Packard Laboratories, Filton Road, Bristol BS12 6QZ, United Kingdom