From 72f0c2764dd22084dc70f9d9bbd8b060cec81e31 Mon Sep 17 00:00:00 2001 From: Fumitoshi UKAI Date: Tue, 13 May 2003 17:08:19 +0000 Subject: [w3m-dev 03898] Re: table rendering * table.c (check_relative_width): added (set_table_matrix): use check_relative_width From: Akinori Ito --- table.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) (limited to 'table.c') diff --git a/table.c b/table.c index cfb8a65..44d6e21 100644 --- a/table.c +++ b/table.c @@ -1,4 +1,4 @@ -/* $Id: table.c,v 1.40 2003/02/20 15:39:22 ukai Exp $ */ +/* $Id: table.c,v 1.41 2003/05/13 17:08:20 ukai Exp $ */ /* * HTML table */ @@ -3490,6 +3490,81 @@ set_table_matrix0(struct table *t, int maxwidth) } } +void +check_relative_width(struct table *t,int maxwidth) +{ + int i; + double rel_total = 0; + int size = t->maxcol+1; + double *rcolwidth = New_N(double,size); + struct table_cell *cell = &t->cell; + int n_leftcol = 0; + + for (i = 0; i < size; i++) + rcolwidth[i] = 0; + + for (i = 0; i < size; i++) { + if (t->fixed_width[i] < 0) + rcolwidth[i] = -(double)t->fixed_width[i]/100.0; + else if (t->fixed_width[i] > 0) + rcolwidth[i] = (double)t->fixed_width[i]/maxwidth; + else + n_leftcol++; + } + for (i = 0; i <= cell->maxcell; i++) { + if (cell->fixed_width[i] < 0) { + double w = -(double)cell->fixed_width[i]/100.0; + double r; + int j,k; + int n_leftcell = 0; + k = cell->col[i]; + r = 0.0; + for (j = 1; j < cell->colspan[i]; j++) { + if (rcolwidth[j+k] > 0) + r += rcolwidth[j+k]; + else + n_leftcell++; + } + if (w < r || (w == r && n_leftcell > 0)) { + cell->fixed_width[i] = -100*r; + } + else { + for (j = 1; j < cell->colspan[i]; j++) { + if (rcolwidth[j+k] == 0) + rcolwidth[j+k] = (w-r)/n_leftcell; + } + } + } + else if (cell->fixed_width[i] > 0) { + /* todo */ + } + } + /* sanity check */ + for (i = 0; i < size; i++) + rel_total += rcolwidth[i]; + + if ((n_leftcol == 0 && rel_total < 0.9) || 1.1 < rel_total) { + for (i = 0; i < size; i++) { + rcolwidth[i] /= rel_total; + } + for (i = 0; i < size; i++) { + if (t->fixed_width[i] < 0) + t->fixed_width[i] = -rcolwidth[i]*100; + } + for (i = 0; i <= cell->maxcell; i++) { + if (cell->fixed_width[i] < 0) { + double r; + int j,k; + k = cell->col[i]; + r = 0.0; + for (j = 1; j < cell->colspan[i]; j++) + r += rcolwidth[j+k]; + cell->fixed_width[i] = -r*100; + } + } + } +} + void set_table_matrix(struct table *t, int width) { @@ -3510,6 +3585,8 @@ set_table_matrix(struct table *t, int width) v_set_val(t->vector, i, 0.); } + check_relative_width(t,width); + for (i = 0; i < size; i++) { if (t->fixed_width[i] > 0) { a = max(t->fixed_width[i], t->minimum_width[i]); -- cgit v1.2.3