~ubuntu-branches/ubuntu/oneiric/gtkhtml3.14/oneiric

« back to all changes in this revision

Viewing changes to gtkhtml/htmltable.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2010-11-02 14:34:48 UTC
  • mfrom: (1.6.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20101102143448-3cxzy1h4oh5v7igz
Tags: 1:3.32.0-0ubuntu1
* New upstream release 3.32.0
  - Crash after closing inline view of text attachment (LP: #178959, #284060)
  - Translations not working in Emoticons, Find/Replace dialogs (LP: #562633)
* debian/patches/gtkhtml3.14_ftbfs.patch: dropped.
* debian/rules: append API_VER for libgtkhtml-editor chrpath as well
* debian/libgtkhtml-editor-dev.install: append api version to pkgconfig
  file name.
* debian/*.shlibs: update shlibs files for new version with same soname, also
  rename libgtkhtml-editor to libgtkhtml-editor-3.14
* debian/control: Replaces/Conflicts gtkhtml3.14 (<< 3.32.0)
* debian/control: bump libgtk2.0-dev and libgail-dev Build-Depends to 2.20
* debian/rules: disable deprecation warnings so the build completes

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
static inline gboolean
73
73
invalid_cell (HTMLTable *table, gint r, gint c)
74
74
{
75
 
        return (table->cells [r][c] == NULL
76
 
                || c != table->cells [r][c]->col
77
 
                || r != table->cells [r][c]->row);
 
75
        return (table->cells[r][c] == NULL
 
76
                || c != table->cells[r][c]->col
 
77
                || r != table->cells[r][c]->row);
78
78
}
79
79
 
80
80
/* HTMLObject methods.  */
94
94
                                if (c == 0)
95
95
                                        break;
96
96
                        }
97
 
                        g_free (table->cells [r]);
 
97
                        g_free (table->cells[r]);
98
98
                        if (r == 0)
99
99
                                break;
100
100
                }
140
140
 
141
141
        d->cells = g_new (HTMLTableCell **, rows);
142
142
        for (r = 0; r < rows; r++)
143
 
                d->cells [r] = g_new0 (HTMLTableCell *, cols);
 
143
                d->cells[r] = g_new0 (HTMLTableCell *, cols);
144
144
 
145
145
        dest->change = HTML_CHANGE_ALL_CALC;
146
146
}
201
201
#endif
202
202
        for (r = 0; r < rows; r++)
203
203
                for (c = 0; c < cols; c++) {
204
 
                        HTMLTableCell *cell = t->cells [start->row + r][c + start_col];
 
204
                        HTMLTableCell *cell = t->cells[start->row + r][c + start_col];
205
205
 
206
206
                        if (!cell || (end->row != start->row
207
207
                                      && ((r == 0 && c < start->col) || (r == rows - 1 && c > end->col)))) {
208
208
                                html_table_set_cell (nt, r, c, html_engine_new_cell (e, nt));
209
 
                                html_table_cell_set_position (nt->cells [r][c], r, c);
 
209
                                html_table_cell_set_position (nt->cells[r][c], r, c);
210
210
                        } else {
211
211
                                if (cell->row == r + start->row && cell->col == c + start_col) {
212
212
                                        HTMLTableCell *cell_copy;
219
219
                                        html_table_cell_set_position (cell_copy, r, c);
220
220
                                } else {
221
221
                                        if (cell->row - start->row >= 0 && cell->col - start_col >= 0) {
222
 
                                                nt->cells [r][c] = nt->cells [cell->row - start->row][cell->col - start_col];
 
222
                                                nt->cells[r][c] = nt->cells[cell->row - start->row][cell->col - start_col];
223
223
                                        } else {
224
224
                                                html_table_set_cell (nt, r, c, html_engine_new_cell (e, nt));
225
 
                                                html_table_cell_set_position (nt->cells [r][c], r, c);
 
225
                                                html_table_cell_set_position (nt->cells[r][c], r, c);
226
226
                                        }
227
227
                                }
228
228
                        }
245
245
 
246
246
        for (r = 0; r < t->totalRows; r++)
247
247
                for (c = 0; c < t->totalCols; c++)
248
 
                        if (t->cells [r][c] && t->cells [r][c]->row == r && t->cells [r][c]->col == c)
249
 
                                n_children ++;
 
248
                        if (t->cells[r][c] && t->cells[r][c]->row == r && t->cells[r][c]->col == c)
 
249
                                n_children++;
250
250
 
251
251
        /* printf ("table n_children %d\n", n_children); */
252
252
 
262
262
 
263
263
        for (r = 0; r < t->totalRows && !child; r++)
264
264
                for (c = 0; c < t->totalCols; c++)
265
 
                        if (t->cells [r][c] && t->cells [r][c]->row == r && t->cells [r][c]->col == c) {
 
265
                        if (t->cells[r][c] && t->cells[r][c]->row == r && t->cells[r][c]->col == c) {
266
266
                                if (n == index) {
267
 
                                        child = HTML_OBJECT (t->cells [r][c]);
 
267
                                        child = HTML_OBJECT (t->cells[r][c]);
268
268
                                        break;
269
269
                                }
270
 
                                n ++;
 
270
                                n++;
271
271
                        }
272
272
 
273
273
        /* printf ("table ref %d child %p\n", index, child); */
284
284
 
285
285
        for (r = 0; r < t->totalRows; r++)
286
286
                for (c = 0; c < t->totalCols; c++) {
287
 
                        if (t->cells [r][c] && t->cells [r][c]->row == r && t->cells [r][c]->col == c) {
288
 
                                if (HTML_OBJECT (t->cells [r][c]) == child) {
 
287
                        if (t->cells[r][c] && t->cells[r][c]->row == r && t->cells[r][c]->col == c) {
 
288
                                if (HTML_OBJECT (t->cells[r][c]) == child) {
289
289
                                        /* printf ("table child %p index %d\n", child, n); */
290
290
                                        return n;
291
291
                                }
292
 
                                n ++;
 
292
                                n++;
293
293
                        }
294
294
                }
295
295
 
306
306
 
307
307
        for (r = 0; r < t->totalRows; r++)
308
308
                for (c = 0; c < t->totalCols; c++)
309
 
                        if (t->cells [r][c] && t->cells [r][c]->row == r && t->cells [r][c]->col == c)
310
 
                                len += html_object_get_recursive_length (HTML_OBJECT (t->cells [r][c])) + 1;
 
309
                        if (t->cells[r][c] && t->cells[r][c]->row == r && t->cells[r][c]->col == c)
 
310
                                len += html_object_get_recursive_length (HTML_OBJECT (t->cells[r][c])) + 1;
311
311
 
312
312
        /* if (len > 0)
313
 
           len --; */
314
 
        len ++;
 
313
           len--; */
 
314
        len++;
315
315
        return len;
316
316
}
317
317
 
338
338
                                cell->row + r, cell->col + c, cell->rspan, cell->cspan, r, c);
339
339
#endif
340
340
 
341
 
                        t->cells [cell->row + r][cell->col + c] = NULL;
 
341
                        t->cells[cell->row + r][cell->col + c] = NULL;
342
342
                }
343
343
        HTML_OBJECT (cell)->parent = NULL;
344
344
}
384
384
 
385
385
        for (r = 0; r < t->totalRows; r++) {
386
386
                for (c = 0; c < t->totalCols; c++) {
387
 
                        cell = t->cells [r][c];
 
387
                        cell = t->cells[r][c];
388
388
                        if (cell && cell->row == r && cell->col == c) {
389
389
                                if (((r == start_row && c < start_col) || r < start_row)
390
390
                                    || ((r == end_row && c > end_col) || r > end_row)) {
391
391
                                        html_table_set_cell (nt, r, c, html_engine_new_cell (e, nt));
392
 
                                        html_table_cell_set_position (nt->cells [r][c], r, c);
 
392
                                        html_table_cell_set_position (nt->cells[r][c], r, c);
393
393
                                } else {
394
394
                                        HTMLTableCell *cell_cut;
395
395
 
402
402
                                        html_table_set_cell (nt, r, c, cell_cut);
403
403
                                        html_table_cell_set_position (cell_cut, r, c);
404
404
 
405
 
                                        if (t->cells [r][c] == NULL) {
 
405
                                        if (t->cells[r][c] == NULL) {
406
406
                                                html_table_set_cell (t, r, c, html_engine_new_cell (e, t));
407
 
                                                html_table_cell_set_position (t->cells [r][c], r, c);
 
407
                                                html_table_cell_set_position (t->cells[r][c], r, c);
408
408
                                        }
409
409
                                }
410
410
                                (*len) ++;
470
470
        dup = HTML_OBJECT (g_new0 (HTMLTable, 1));
471
471
        dup_table = HTML_TABLE (dup);
472
472
        copy_sized (self, dup, t->totalRows, t->totalCols);
473
 
        for (r = 0; r < t->totalRows; r ++) {
474
 
                for (c = 0; c < t->totalCols; c ++) {
 
473
        for (r = 0; r < t->totalRows; r++) {
 
474
                for (c = 0; c < t->totalCols; c++) {
475
475
                        HTMLTableCell *cc;
476
476
 
477
 
                        cc = t->cells [r][c];
 
477
                        cc = t->cells[r][c];
478
478
                        if (cc && cc->row == r && cc->col == c) {
479
479
                                if ((r == cell->row && c < cell->col) || r < cell->row) {
480
480
                                        /* empty cell in dup table */
481
481
                                        html_table_set_cell (dup_table, r, c, html_engine_new_cell (e, dup_table));
482
 
                                        html_table_cell_set_position (dup_table->cells [r][c], r, c);
 
482
                                        html_table_cell_set_position (dup_table->cells[r][c], r, c);
483
483
                                } else if ((r == dup_cell->row && c > dup_cell->col) || r > dup_cell->row) {
484
484
                                        /* move cc to dup table */
485
485
                                        remove_cell (t, cc);
486
486
                                        html_table_set_cell (dup_table, r, c, cc);
487
 
                                        html_table_cell_set_position (dup_table->cells [r][c], r, c);
 
487
                                        html_table_cell_set_position (dup_table->cells[r][c], r, c);
488
488
                                        /* place empty cell in t table */
489
489
                                        html_table_set_cell (t, r, c, html_engine_new_cell (e, t));
490
 
                                        html_table_cell_set_position (t->cells [r][c], r, c);
 
490
                                        html_table_cell_set_position (t->cells[r][c], r, c);
491
491
 
492
492
                                } else {
493
493
                                        if (r == cell->row && c == cell->col) {
495
495
                                                        /* empty cell in dup table */
496
496
                                                        html_table_set_cell (dup_table, r, c,
497
497
                                                                             html_engine_new_cell (e, dup_table));
498
 
                                                        html_table_cell_set_position (dup_table->cells [r][c], r, c);
 
498
                                                        html_table_cell_set_position (dup_table->cells[r][c], r, c);
499
499
                                                }
500
500
 
501
501
                                        }
506
506
                                                        remove_cell (t, cell);
507
507
 
508
508
                                                html_table_set_cell (dup_table, r, c, dup_cell);
509
 
                                                html_table_cell_set_position (dup_table->cells [r][c], r, c);
 
509
                                                html_table_cell_set_position (dup_table->cells[r][c], r, c);
510
510
 
511
511
                                                if (r != cell->row || c != cell->col) {
512
512
                                                        /* empty cell in orig table */
513
513
                                                        html_table_set_cell (t, r, c, html_engine_new_cell (e, t));
514
 
                                                        html_table_cell_set_position (t->cells [r][c], r, c);
 
514
                                                        html_table_cell_set_position (t->cells[r][c], r, c);
515
515
                                                }
516
516
                                        }
517
517
                                }
558
558
            || t1->totalCols != t2->totalCols || t1->totalRows != t2->totalRows)
559
559
                return FALSE;
560
560
 
561
 
        for (r = 0; r < t1->totalRows; r ++) {
562
 
                for (c = 0; c < t1->totalCols; c ++) {
 
561
        for (r = 0; r < t1->totalRows; r++) {
 
562
                for (c = 0; c < t1->totalCols; c++) {
563
563
                        HTMLTableCell *c1, *c2;
564
564
 
565
 
                        c1 = t1->cells [r][c];
566
 
                        c2 = t2->cells [r][c];
 
565
                        c1 = t1->cells[r][c];
 
566
                        c2 = t2->cells[r][c];
567
567
                        if (!c1 || !c2)
568
568
                                return FALSE;
569
569
 
612
612
        html_object_destroy (HTML_OBJECT (c1));
613
613
        remove_cell (t2, c2);
614
614
        html_table_set_cell (t1, r, c, c2);
615
 
        html_table_cell_set_position (t1->cells [r][c], r, c);
 
615
        html_table_cell_set_position (t1->cells[r][c], r, c);
616
616
}
617
617
 
618
618
static gboolean
653
653
                cursor_cell_2 = HTML_TABLE_CELL (object_get_parent_cell (cursor->object, HTML_OBJECT (t1)));
654
654
        cursor_cell_3 = HTML_TABLE_CELL (object_get_parent_cell (e->cursor->object, HTML_OBJECT (t2)));
655
655
 
656
 
        for (r = 0; r < t1->totalRows; r ++) {
657
 
                for (c = 0; c < t1->totalCols; c ++) {
 
656
        for (r = 0; r < t1->totalRows; r++) {
 
657
                for (c = 0; c < t1->totalCols; c++) {
658
658
                        HTMLTableCell *c1, *c2;
659
659
 
660
 
                        c1 = t1->cells [r][c];
661
 
                        c2 = t2->cells [r][c];
 
660
                        c1 = t1->cells[r][c];
 
661
                        c2 = t2->cells[r][c];
662
662
 
663
663
                        if (first) {
664
664
                                if (!html_clue_is_empty (HTML_CLUE (c2))) {
680
680
                                                                + (t1->totalCols - c1->col);
681
681
                                                        for (list = *left; list; list = list->next)
682
682
                                                                if (list->data && HTML_IS_TABLE (list->data))
683
 
                                                                        e->cursor->position --;
 
683
                                                                        e->cursor->position--;
684
684
 
685
685
                                                        /* printf ("3rd dec: %d t1_tail %d,%d\n",
686
686
                                                                (t1->totalRows - c1->row - 1)*t1->totalCols
772
772
        gint i;
773
773
        if (c)
774
774
                for (i=0; i < table->totalRows - 1; i++)
775
 
                        if (table->cells [i][c - 1])
776
 
                                do_cspan (table, i, c, table->cells [i][c - 1]);
 
775
                        if (table->cells[i][c - 1])
 
776
                                do_cspan (table, i, c, table->cells[i][c - 1]);
777
777
}
778
778
 
779
779
static void
782
782
        gint r;
783
783
 
784
784
        for (r = 0; r < table->allocRows; r++) {
785
 
                table->cells [r] = g_renew (HTMLTableCell *, table->cells [r], table->totalCols + num);
786
 
                memset (table->cells [r] + table->totalCols, 0, num * sizeof (HTMLTableCell *));
 
785
                table->cells[r] = g_renew (HTMLTableCell *, table->cells[r], table->totalCols + num);
 
786
                memset (table->cells[r] + table->totalCols, 0, num * sizeof (HTMLTableCell *));
787
787
        }
788
788
        table->totalCols += num;
789
789
}
803
803
        table->cells = g_renew (HTMLTableCell **, table->cells, table->allocRows + num);
804
804
 
805
805
        for (r = table->allocRows; r < table->allocRows + num; r++) {
806
 
                table->cells [r] = g_new (HTMLTableCell *, table->totalCols);
807
 
                memset (table->cells [r], 0, table->totalCols * sizeof (HTMLTableCell *));
 
806
                table->cells[r] = g_new (HTMLTableCell *, table->totalCols);
 
807
                memset (table->cells[r], 0, table->totalCols * sizeof (HTMLTableCell *));
808
808
        }
809
809
 
810
810
        table->allocRows += num;
869
869
                                        if (LL col_width * (ARR (cell->col + i + 1) - ARR (cell->col))
870
870
                                            - LL new_width * span_width > LL (new_width + 1) * span_width
871
871
                                            - LL col_width * (ARR (cell->col + i + 1) - ARR (cell->col)))
872
 
                                                new_width ++;
 
872
                                                new_width++;
873
873
                                } else {
874
874
                                        new_width = added + col_width / span;
875
875
                                        if (col_width - LL span * new_width > LL span * (new_width + 1) - col_width)
876
 
                                                new_width ++;
 
876
                                                new_width++;
877
877
                                }
878
878
                                new_width -= added;
879
879
                                added     += new_width;
880
880
 
881
 
                                if (sizes [cell->col + i] < new_width)
882
 
                                        sizes [cell->col + i] = new_width;
 
881
                                if (sizes[cell->col + i] < new_width)
 
882
                                        sizes[cell->col + i] = new_width;
883
883
                        }
884
884
                        /* printf ("%d added %d col_width %d span_width %d\n",
885
885
                           col_width - added, added, col_width, span_width); */
911
911
                add  = 0;
912
912
                for (c = 0; c < table->totalCols; c++) {
913
913
                        ARR (c + 1) += add;
914
 
                        if (ARR (c + 1) - ARR (c) < arr [c]) {
915
 
                                add += arr [c] - (ARR (c + 1) - ARR (c));
916
 
                                ARR (c + 1) = ARR (c) + arr [c];
 
914
                        if (ARR (c + 1) - ARR (c) < arr[c]) {
 
915
                                add += arr[c] - (ARR (c + 1) - ARR (c));
 
916
                                ARR (c + 1) = ARR (c) + arr[c];
917
917
                        }
918
918
                }
919
919
                g_free (arr);
920
 
                span ++;
 
920
                span++;
921
921
        }
922
922
 
923
923
        for (c = 0; c < table->totalCols; c++)
942
942
        g_assert (row >= 0);
943
943
 
944
944
        /* add previous column cell which has cspan > 1 */
945
 
        while (table->col < table->totalCols && table->cells [row][table->col] != 0) {
946
 
                html_table_alloc_cell (table, row, table->col + table->cells [row][table->col]->cspan);
947
 
                do_cspan (table, row, table->col + 1, table->cells [row][table->col]);
948
 
                table->col += (table->cells [row][table->col])->cspan;
 
945
        while (table->col < table->totalCols && table->cells[row][table->col] != 0) {
 
946
                html_table_alloc_cell (table, row, table->col + table->cells[row][table->col]->cspan);
 
947
                do_cspan (table, row, table->col + 1, table->cells[row][table->col]);
 
948
                table->col += (table->cells[row][table->col])->cspan;
949
949
        }
950
950
}
951
951
 
957
957
        g_assert (row > 0);
958
958
 
959
959
        for (i=0; i<table->totalCols; i++)
960
 
                if (table->cells [row - 1][i]
961
 
                    && (table->cells [row - 1][i])->row + (table->cells [row - 1][i])->rspan
 
960
                if (table->cells[row - 1][i]
 
961
                    && (table->cells[row - 1][i])->row + (table->cells[row - 1][i])->rspan
962
962
                    > row) {
963
 
                        html_table_set_cell (table, table->row, i, table->cells [table->row - 1][i]);
964
 
                        do_cspan (table, table->row, i + 1, table->cells [table->row -1][i]);
 
963
                        html_table_set_cell (table, table->row, i, table->cells[table->row - 1][i]);
 
964
                        do_cspan (table, table->row, i + 1, table->cells[table->row -1][i]);
965
965
                }
966
966
}
967
967
 
968
968
void
969
969
html_table_set_cell (HTMLTable *table, gint r, gint c, HTMLTableCell *cell)
970
970
{
971
 
        if (!table->cells [r][c]) {
 
971
        if (!table->cells[r][c]) {
972
972
#ifdef GTKHTML_DEBUG_TABLE
973
973
                printf ("set cell:    %d,%d %p\n", r, c, cell);
974
974
#endif
975
 
                table->cells [r][c] = cell;
 
975
                table->cells[r][c] = cell;
976
976
                HTML_OBJECT (cell)->parent = HTML_OBJECT (table);
977
977
        }
978
978
}
1244
1244
 
1245
1245
                        if (cell == NULL)
1246
1246
                                continue;
1247
 
                        if (c < end_col && cell == table->cells [r][c + 1])
 
1247
                        if (c < end_col && cell == table->cells[r][c + 1])
1248
1248
                                continue;
1249
 
                        if (r < end_row && table->cells [r + 1][c] == cell)
 
1249
                        if (r < end_row && table->cells[r + 1][c] == cell)
1250
1250
                                continue;
1251
1251
 
1252
1252
                        html_object_draw (HTML_OBJECT (cell), p,
1361
1361
                                continue;
1362
1362
 
1363
1363
                        cl = cell_end_col (table, cell);
1364
 
                        if (col_percent [cl] - col_percent [c] < cell->fixed_width) {
 
1364
                        if (col_percent[cl] - col_percent[c] < cell->fixed_width) {
1365
1365
                                gint cp, part, added, pleft, not_percented, np;
1366
1366
                                part = 0;
1367
1367
                                not_percented = 0;
1368
1368
                                for (cp = 0; cp < span; cp++)
1369
1369
                                        if (!PERC (c + cp))
1370
 
                                                not_percented ++;
 
1370
                                                not_percented++;
1371
1371
 
1372
1372
                                np    = 1;
1373
1373
                                added = 0;
1374
 
                                pleft = cell->fixed_width - (col_percent [cl] - col_percent [c]);
 
1374
                                pleft = cell->fixed_width - (col_percent[cl] - col_percent[c]);
1375
1375
                                for (cp = 0; cp < span; cp++) {
1376
1376
                                        if (not_percented) {
1377
1377
                                                if (!PERC (c + cp)) {
1379
1379
                                                        if (np * pleft - part * not_percented >
1380
1380
                                                            (part + 1) * not_percented - np * pleft)
1381
1381
                                                                part++;
1382
 
                                                        np ++;
 
1382
                                                        np++;
1383
1383
                                                }
1384
1384
                                        } else {
1385
 
                                                part = ((col_percent [c + cp + 1] - col_percent [c]) * pleft)
1386
 
                                                        / (col_percent [cl] - col_percent [cell->col]);
1387
 
                                                if ((col_percent [c + cp + 1] - col_percent [c]) * pleft
1388
 
                                                    - part * (col_percent [cl] - col_percent [c])
1389
 
                                                    > (part + 1) * (col_percent [cl] - col_percent [c])
1390
 
                                                    - (col_percent [c + cp + 1] - col_percent [c]) * pleft)
1391
 
                                                        part ++;
 
1385
                                                part = ((col_percent[c + cp + 1] - col_percent[c]) * pleft)
 
1386
                                                        / (col_percent[cl] - col_percent[cell->col]);
 
1387
                                                if ((col_percent[c + cp + 1] - col_percent[c]) * pleft
 
1388
                                                    - part * (col_percent[cl] - col_percent[c])
 
1389
                                                    > (part + 1) * (col_percent[cl] - col_percent[c])
 
1390
                                                    - (col_percent[c + cp + 1] - col_percent[c]) * pleft)
 
1391
                                                        part++;
1392
1392
                                        }
1393
1393
                                        part  -= added;
1394
1394
                                        added += part;
1395
 
                                        span_percent [c + cp] = PERC (c + cp) + part;
 
1395
                                        span_percent[c + cp] = PERC (c + cp) + part;
1396
1396
                                }
1397
1397
                        }
1398
1398
                }
1407
1407
        gboolean next = TRUE;
1408
1408
 
1409
1409
        percent = g_new0 (gint, table->totalCols);
1410
 
        for (span = 1; next && span <= table->totalCols; span ++) {
 
1410
        for (span = 1; next && span <= table->totalCols; span++) {
1411
1411
                for (c = 0; c < table->totalCols; c++)
1412
 
                        percent [c] = 0;
 
1412
                        percent[c] = 0;
1413
1413
 
1414
1414
                next    = calc_percentage_step (table, col_percent, percent, span);
1415
1415
                add     = 0;
1416
1416
 
1417
1417
                for (c = 0; c < table->totalCols; c++) {
1418
 
                        col_percent [c + 1] += add;
1419
 
                        if (PERC (c) < percent [c]) {
1420
 
                                add += percent [c] - PERC (c);
1421
 
                                col_percent [c + 1] = col_percent [c] + percent [c];
 
1418
                        col_percent[c + 1] += add;
 
1419
                        if (PERC (c) < percent[c]) {
 
1420
                                add += percent[c] - PERC (c);
 
1421
                                col_percent[c + 1] = col_percent[c] + percent[c];
1422
1422
                        }
1423
1423
                }
1424
1424
        }
1432
1432
 
1433
1433
        not_percented = 0;
1434
1434
        for (c = 0; c < table->totalCols; c++)
1435
 
                if (col_percent [c + 1] == col_percent [c])
1436
 
                        not_percented ++;
 
1435
                if (col_percent[c + 1] == col_percent[c])
 
1436
                        not_percented++;
1437
1437
 
1438
1438
        return not_percented;
1439
1439
}
1446
1446
        to_fill = 0;
1447
1447
        for (c = 0; c < table->totalCols; c++) {
1448
1448
                request = (LL max_width * (PERC (c))) / 100;
1449
 
                if (max_size [c] < request)
1450
 
                        to_fill += request - max_size [c];
 
1449
                if (max_size[c] < request)
 
1450
                        to_fill += request - max_size[c];
1451
1451
        }
1452
1452
 
1453
1453
        /* printf ("to fill %d\n", to_fill); */
1457
1457
        if (left) {
1458
1458
                for (c = 0; c < table->totalCols; c++) {
1459
1459
                        request = (LL max_width * (PERC (c))) / 100;
1460
 
                        if (max_size [c] < request) {
1461
 
                                add     = LL left * (request - max_size [c] + filled) / to_fill;
1462
 
                                if (LL left * (request - max_size [c] + filled) - LL add * to_fill >
1463
 
                                    LL (add + 1) * to_fill - LL left * (request - max_size [c] + filled))
1464
 
                                        add ++;
 
1460
                        if (max_size[c] < request) {
 
1461
                                add     = LL left * (request - max_size[c] + filled) / to_fill;
 
1462
                                if (LL left * (request - max_size[c] + filled) - LL add * to_fill >
 
1463
                                    LL (add + 1) * to_fill - LL left * (request - max_size[c] + filled))
 
1464
                                        add++;
1465
1465
                                add          -= added;
1466
1466
                                added        += add;
1467
 
                                filled       += request - max_size [c];
1468
 
                                max_size [c] += add;
 
1467
                                filled       += request - max_size[c];
 
1468
                                max_size[c] += add;
1469
1469
                        }
1470
1470
                }
1471
1471
        }
1485
1485
        *ret_total_pref = 0;
1486
1486
        *ret_total = 0;
1487
1487
        for (c = 0; c < table->totalCols; c++)
1488
 
                if (col_percent [c + 1] == col_percent [c]) {
 
1488
                if (col_percent[c + 1] == col_percent[c]) {
1489
1489
                        pw = PREF (c + 1) - PREF (c)
1490
1490
                                - pixel_size * (table->spacing + border_extra);
1491
1491
                        /* printf ("col %d pw %d size %d\n", c, pw, max_size [c]); */
1492
 
                        if (max_size [c] < pw) {
1493
 
                                if (pw - max_size [c] < min_fill) {
 
1492
                        if (max_size[c] < pw) {
 
1493
                                if (pw - max_size[c] < min_fill) {
1494
1494
                                        *ret_col = c;
1495
 
                                        min_fill = pw - max_size [c];
 
1495
                                        min_fill = pw - max_size[c];
1496
1496
                                }
1497
1497
 
1498
1498
                                (*ret_total_pref) += pw;
1499
 
                                (*ret_total) += max_size [c];
 
1499
                                (*ret_total) += max_size[c];
1500
1500
                        }
1501
1501
                }
1502
1502
 
1516
1516
                        - pixel_size * (table->spacing + border_extra);
1517
1517
                /* printf ("min: %d left: %d\n", min_col, left); */
1518
1518
                to_divide = MIN (total_pref - total, left);
1519
 
                if (min_pw - max_size [min_col] < ((gdouble) min_pw * to_divide) / total_pref) {
1520
 
                        added = min_pw - max_size [min_col];
 
1519
                if (min_pw - max_size[min_col] < ((gdouble) min_pw * to_divide) / total_pref) {
 
1520
                        added = min_pw - max_size[min_col];
1521
1521
                        left -= added;
1522
1522
                        min_fill = to_divide - added;
1523
 
                        max_size [min_col] += added;
 
1523
                        max_size[min_col] += added;
1524
1524
                        total_pref -= min_pw;
1525
1525
                } else {
1526
1526
                        min_fill = to_divide;
1531
1531
                added = 0;
1532
1532
 
1533
1533
                for (c = 0; c < table->totalCols; c++) {
1534
 
                        if (col_percent [c + 1] == col_percent [c]) {
 
1534
                        if (col_percent[c + 1] == col_percent[c]) {
1535
1535
                                pw = PREF (c + 1) - PREF (c)
1536
1536
                                        - pixel_size * (table->spacing + border_extra);
1537
 
                                if (max_size [c] < pw) {
 
1537
                                if (max_size[c] < pw) {
1538
1538
                                        processed_pw += pw;
1539
1539
                                        part = (LL min_fill * processed_pw) / total_pref;
1540
1540
                                        if (LL min_fill * processed_pw - LL part * total_pref
1541
1541
                                            > LL (part + 1) * total_pref - LL min_fill * processed_pw)
1542
 
                                                part ++;
 
1542
                                                part++;
1543
1543
                                        part         -= added;
1544
 
                                        if (max_size [c] + part > pw)
1545
 
                                                part = pw - max_size [c];
 
1544
                                        if (max_size[c] + part > pw)
 
1545
                                                part = pw - max_size[c];
1546
1546
                                        added        += part;
1547
 
                                        max_size [c] += part;
 
1547
                                        max_size[c] += part;
1548
1548
                                        left         -= part;
1549
1549
                                        /* printf ("cell %d add: %d --> %d\n", c, part, max_size [c]); */
1550
1550
                                }
1569
1569
#define FW(c) COLUMN_FIX (table, c + 1) - COLUMN_FIX (table, c)
1570
1570
        pref = 0;
1571
1571
        for (c = 0; c < table->totalCols; c++)
1572
 
                if (col_percent [c + 1] == col_percent [c] && PW (c) > FW (c))
 
1572
                if (col_percent[c + 1] == col_percent[c] && PW (c) > FW (c))
1573
1573
                        pref += COLUMN_PREF (table, c + 1) - COLUMN_PREF (table, c)
1574
1574
                                - pixel_size * (table->spacing + border_extra);
1575
1575
                        /* printf ("col pref: %d size: %d\n", COLUMN_PREF (table, c + 1)
1576
1576
                           - COLUMN_PREF (table, c)
1577
 
                           - pixel_size * (table->spacing + border_extra), max_size [c]); */
 
1577
                           - pixel_size * (table->spacing + border_extra), max_size[c]); */
1578
1578
 
1579
1579
        added        = 0;
1580
1580
        processed_pw = 0;
1582
1582
 
1583
1583
        if (pref)
1584
1584
                for (c = 0; c < table->totalCols; c++) {
1585
 
                        if (col_percent [c + 1] == col_percent [c] && PW (c) > FW (c)) {
 
1585
                        if (col_percent[c + 1] == col_percent[c] && PW (c) > FW (c)) {
1586
1586
                                pw  = COLUMN_PREF (table, c + 1) - COLUMN_PREF (table, c)
1587
1587
                                        - pixel_size * (table->spacing + border_extra);
1588
1588
                                processed_pw += pw;
1591
1591
                                   pw, part, total_fill, processed_pw); */
1592
1592
                                if (LL total_fill * processed_pw - LL part * pref
1593
1593
                                    > LL (part + 1) * pref - LL total_fill * processed_pw)
1594
 
                                        part ++;
 
1594
                                        part++;
1595
1595
                                part         -= added;
1596
 
                                max_size [c] += part;
 
1596
                                max_size[c] += part;
1597
1597
                                added        += part;
1598
1598
                                left         -= part;
1599
1599
                                /* printf ("col %d (add %d) --> %d (pw=%d)\n", c, part, max_size [c], pw); */
1626
1626
 
1627
1627
        active = g_new (gboolean, table->totalCols);
1628
1628
        for (c = 0; c < table->totalCols; c++)
1629
 
                active [c] = TRUE;
 
1629
                active[c] = TRUE;
1630
1630
 
1631
 
        percent = col_percent [table->totalCols];
 
1631
        percent = col_percent[table->totalCols];
1632
1632
        width   = max_width;
1633
1633
        do {
1634
1634
                sub_percent = 0.0;
1635
1635
                sub_width   = width;
1636
1636
                all_active  = TRUE;
1637
1637
                for (c = 0; c < table->totalCols; c++) {
1638
 
                        if (active [c]) {
1639
 
                                if (max_size [c] < ((gdouble) width * PERC (c)) / percent)
 
1638
                        if (active[c]) {
 
1639
                                if (max_size[c] < ((gdouble) width * PERC (c)) / percent)
1640
1640
                                        sub_percent += PERC (c);
1641
1641
                                else {
1642
 
                                        sub_width -= max_size [c];
 
1642
                                        sub_width -= max_size[c];
1643
1643
                                        all_active = FALSE;
1644
 
                                        active [c] = FALSE;
 
1644
                                        active[c] = FALSE;
1645
1645
                                }
1646
1646
                        }
1647
1647
                }
1651
1651
 
1652
1652
        /* printf ("sub_width %d\n", sub_width); */
1653
1653
        for (c = 0; c < table->totalCols; c++)
1654
 
                if (active [c] && max_size [c] < ((gdouble) width * PERC (c)) / percent)
1655
 
                        max_size [c] = ((gdouble) width) * (PERC (c)) / percent;
 
1654
                if (active[c] && max_size[c] < ((gdouble) width * PERC (c)) / percent)
 
1655
                        max_size[c] = ((gdouble) width) * (PERC (c)) / percent;
1656
1656
 
1657
1657
        g_free (active);
1658
1658
}
1671
1671
                for (c = 0; c < table->totalCols; c++) {
1672
1672
                        cell = table->cells[r][c];
1673
1673
                        if (cell) {
1674
 
                                size = max_size [c] + (cell->col != c ? size : 0);
 
1674
                                size = max_size[c] + (cell->col != c ? size : 0);
1675
1675
                                if (cell_end_col (table, cell) - 1 == c && cell->row == r)
1676
1676
                                        html_object_set_max_width (HTML_OBJECT (cell), painter, size
1677
1677
                                                                   + pixel_size * (table->spacing + border_extra) * CSPAN);
1688
1688
        COLUMN_OPT (table, 0) = COLUMN_MIN (table, 0);
1689
1689
 
1690
1690
        for (c = 0; c < table->totalCols; c++)
1691
 
                COLUMN_OPT (table, c + 1) = COLUMN_OPT (table, c) + max_size [c]
 
1691
                COLUMN_OPT (table, c + 1) = COLUMN_OPT (table, c) + max_size[c]
1692
1692
                        + pixel_size * (table->spacing + (table->border ? 2 : 0));
1693
1693
}
1694
1694
 
1703
1703
 
1704
1704
        col_percent  = g_new (gint, table->totalCols + 1);
1705
1705
        for (c = 0; c <= table->totalCols; c++)
1706
 
                col_percent [c] = 0;
 
1706
                col_percent[c] = 0;
1707
1707
 
1708
1708
        calc_col_percentage (table, col_percent);
1709
1709
        /* printf ("width_left: %d percented: %d\n", width_left, col_percent [table->totalCols]); */
1729
1729
 
1730
1730
        max_size = g_new (gint, table->totalCols);
1731
1731
        for (c = 0; c < table->totalCols; c++)
1732
 
                max_size [c] = COLUMN_MIN (table, c+1) - COLUMN_MIN (table, c) - pixel_size * (table->spacing + border_extra);
 
1732
                max_size[c] = COLUMN_MIN (table, c+1) - COLUMN_MIN (table, c) - pixel_size * (table->spacing + border_extra);
1733
1733
 
1734
1734
        return max_size;
1735
1735
}
2031
2031
                        /* remove last \n from added text */
2032
2032
                        if (buffer->len != len) {
2033
2033
                                tab = TRUE;
2034
 
                                if (buffer->str [buffer->len-1] == '\n')
 
2034
                                if (buffer->str[buffer->len-1] == '\n')
2035
2035
                                        g_string_truncate (buffer, buffer->len - 1);
2036
2036
                        }
2037
2037
                }
2053
2053
                for (c = 0; c < table->totalCols; c++) {
2054
2054
                        if (invalid_cell (table, r, c))
2055
2055
                                continue;
2056
 
                        return HTML_OBJECT (table->cells [r][c]);
 
2056
                        return HTML_OBJECT (table->cells[r][c]);
2057
2057
                }
2058
2058
        return NULL;
2059
2059
}
2069
2069
                for (c = table->totalCols - 1; c >= 0; c--) {
2070
2070
                        if (invalid_cell (table, r, c))
2071
2071
                                continue;
2072
 
                        return HTML_OBJECT (table->cells [r][c]);
 
2072
                        return HTML_OBJECT (table->cells[r][c]);
2073
2073
                }
2074
2074
        return NULL;
2075
2075
}
2087
2087
                for (; c < table->totalCols; c++) {
2088
2088
                        if (invalid_cell (table, r, c))
2089
2089
                                continue;
2090
 
                        return HTML_OBJECT (table->cells [r][c]);
 
2090
                        return HTML_OBJECT (table->cells[r][c]);
2091
2091
                }
2092
2092
                c = 0;
2093
2093
        }
2107
2107
                for (; c >=0; c--) {
2108
2108
                        if (invalid_cell (table, r, c))
2109
2109
                                continue;
2110
 
                        return HTML_OBJECT (table->cells [r][c]);
 
2110
                        return HTML_OBJECT (table->cells[r][c]);
2111
2111
                }
2112
2112
                c = table->totalCols-1;
2113
2113
        }
2156
2156
        for (r = 0; r < table->totalRows; r++) {
2157
2157
                SB "<TR>\n" SE;
2158
2158
                for (c = 0; c < table->totalCols; c++) {
2159
 
                        if (!table->cells [r][c]
2160
 
                            || table->cells [r][c]->row != r
2161
 
                            || table->cells [r][c]->col != c)
 
2159
                        if (!table->cells[r][c]
 
2160
                            || table->cells[r][c]->row != r
 
2161
                            || table->cells[r][c]->col != c)
2162
2162
                                continue;
2163
 
                        if (!html_object_save (HTML_OBJECT (table->cells [r][c]), state))
 
2163
                        if (!html_object_save (HTML_OBJECT (table->cells[r][c]), state))
2164
2164
                                return FALSE;
2165
2165
                }
2166
2166
                SB "</TR>\n" SE;
2183
2183
 
2184
2184
        for (r = 0; r < table->totalRows; r++) {
2185
2185
                for (c = 0; c < table->totalCols; c++) {
2186
 
                        if (!table->cells [r][c]
2187
 
                            || table->cells [r][c]->row != r
2188
 
                            || table->cells [r][c]->col != c)
 
2186
                        if (!table->cells[r][c]
 
2187
                            || table->cells[r][c]->row != r
 
2188
                            || table->cells[r][c]->col != c)
2189
2189
                                continue;
2190
2190
                        /*  FIXME the width calculation for the column here is completely broken */
2191
 
                        result &= html_object_save_plain (HTML_OBJECT (table->cells [r][c]), state, requested_width / table->totalCols);
 
2191
                        result &= html_object_save_plain (HTML_OBJECT (table->cells[r][c]), state, requested_width / table->totalCols);
2192
2192
                }
2193
2193
        }
2194
2194
 
2385
2385
        prev_col_do_cspan (table, table->row);
2386
2386
 
2387
2387
        /* look for first free cell */
2388
 
        while (table->cells [table->row][table->col] && table->col < table->totalCols)
 
2388
        while (table->cells[table->row][table->col] && table->col < table->totalCols)
2389
2389
                table->col++;
2390
2390
 
2391
2391
        html_table_alloc_cell (table, table->row, table->col);
2413
2413
{
2414
2414
        gint r, c, cells = 0;
2415
2415
 
2416
 
        for (r = 0; r < table->totalRows; r ++)
2417
 
                for (c = 0; c < table->totalCols; c ++)
2418
 
                        if (table->cells [r][c]) {
2419
 
                                if (HTML_CLUE (table->cells [r][c])->head == NULL) {
2420
 
                                        HTMLTableCell *cell = table->cells [r][c];
 
2416
        for (r = 0; r < table->totalRows; r++)
 
2417
                for (c = 0; c < table->totalCols; c++)
 
2418
                        if (table->cells[r][c]) {
 
2419
                                if (HTML_CLUE (table->cells[r][c])->head == NULL) {
 
2420
                                        HTMLTableCell *cell = table->cells[r][c];
2421
2421
 
2422
2422
                                        remove_cell (table, cell);
2423
2423
                                        html_object_destroy (HTML_OBJECT (cell));
2424
2424
                                } else
2425
 
                                        cells ++;
 
2425
                                        cells++;
2426
2426
                        }
2427
2427
        return cells;
2428
2428
}