From 35fab6526c3b8491a05769cb72e24c00316c5d3f Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 13 Jul 2014 10:47:43 -0700 Subject: [PATCH] render: Don't add overflows when header is contiguous with body. render_page_select() needs to calculate overflows when it cuts a header off from the body of a table. Until now, it has considered headers and body to always be cut off from each other, but this isn't true when the selected body region is adjacent to one of the headers. This commit takes that into consideration, producing better results in one of the tests in the testsuite. This commit is much smaller when viewed with whitespace changes ignored. --- src/output/render.c | 84 +++++++++++++++++++++--------------------- tests/output/render.at | 2 +- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/src/output/render.c b/src/output/render.c index d8c25c2a38..0ef78f1af6 100644 --- a/src/output/render.c +++ b/src/output/render.c @@ -1288,50 +1288,52 @@ render_page_select (const struct render_page *page, enum table_axis axis, s.p1 = p1; s.subpage = subpage; - for (z = 0; z < page->n[b]; z++) - { - struct table_cell cell; - int d[TABLE_N_AXES]; + if (!page->h[a][0] || z0 > page->h[a][0] || p0) + for (z = 0; z < page->n[b]; z++) + { + struct table_cell cell; + int d[TABLE_N_AXES]; - d[a] = z0; - d[b] = z; - table_get_cell (page->table, d[H], d[V], &cell); - if ((z == cell.d[b][0] && (p0 || cell.d[a][0] < z0)) - || (z == cell.d[b][1] - 1 && p1)) - { - ro = insert_overflow (&s, &cell); - ro->overflow[a][0] += p0 + axis_width (page, a, - cell_ofs (cell.d[a][0]), - cell_ofs (z0)); - if (z1 == z0 + 1) - ro->overflow[a][1] += p1; - if (page->h[a][0] && page->h[a][1]) - ro->overflow[a][0] -= page->join_crossing[a][cell.d[a][0] + 1]; - if (cell.d[a][1] > z1) + d[a] = z0; + d[b] = z; + table_get_cell (page->table, d[H], d[V], &cell); + if ((z == cell.d[b][0] && (p0 || cell.d[a][0] < z0)) + || (z == cell.d[b][1] - 1 && p1)) + { + ro = insert_overflow (&s, &cell); + ro->overflow[a][0] += p0 + axis_width (page, a, + cell_ofs (cell.d[a][0]), + cell_ofs (z0)); + if (z1 == z0 + 1) + ro->overflow[a][1] += p1; + if (page->h[a][0] && page->h[a][1]) + ro->overflow[a][0] -= page->join_crossing[a][cell.d[a][0] + 1]; + if (cell.d[a][1] > z1) + ro->overflow[a][1] += axis_width (page, a, cell_ofs (z1), + cell_ofs (cell.d[a][1])); + } + table_cell_free (&cell); + } + + if (!page->h[a][1] || z1 < page->n[a] - page->h[a][1] || p1) + for (z = 0; z < page->n[b]; z++) + { + struct table_cell cell; + int d[TABLE_N_AXES]; + + /* XXX need to handle p1 below */ + d[a] = z1 - 1; + d[b] = z; + table_get_cell (page->table, d[H], d[V], &cell); + if (z == cell.d[b][0] && cell.d[a][1] > z1 + && find_overflow_for_cell (&s, &cell) == NULL) + { + ro = insert_overflow (&s, &cell); ro->overflow[a][1] += axis_width (page, a, cell_ofs (z1), cell_ofs (cell.d[a][1])); - } - table_cell_free (&cell); - } - - for (z = 0; z < page->n[b]; z++) - { - struct table_cell cell; - int d[TABLE_N_AXES]; - - /* XXX need to handle p1 below */ - d[a] = z1 - 1; - d[b] = z; - table_get_cell (page->table, d[H], d[V], &cell); - if (z == cell.d[b][0] && cell.d[a][1] > z1 - && find_overflow_for_cell (&s, &cell) == NULL) - { - ro = insert_overflow (&s, &cell); - ro->overflow[a][1] += axis_width (page, a, cell_ofs (z1), - cell_ofs (cell.d[a][1])); - } - table_cell_free (&cell); - } + } + table_cell_free (&cell); + } /* Copy overflows from PAGE into subpage. */ HMAP_FOR_EACH (ro, struct render_overflow, node, &page->overflows) diff --git a/tests/output/render.at b/tests/output/render.at index 4bc14d809b..66ae86f747 100644 --- a/tests/output/render.at +++ b/tests/output/render.at @@ -789,7 +789,7 @@ op|h|q| +-+-+r| |xyz|s| +-+-+-+ -|E| F| +|E|FGH| +-+-+-+ |L|O|P| |M+-+-+ -- 2.30.2