render: Don't add overflows when header is contiguous with body.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 13 Jul 2014 17:47:43 +0000 (10:47 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 13 Jul 2014 17:47:43 +0000 (10:47 -0700)
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
tests/output/render.at

index d8c25c2a38d29ccf36544b50d129b94c8d7c94e9..0ef78f1af653b27bac865404a255df2aadaaa6eb 100644 (file)
@@ -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)
index 4bc14d809bb4c3bd86e40b6d9199633b31039fe9..66ae86f7470bbd6083c71fdf7457fa260907c2f2 100644 (file)
@@ -789,7 +789,7 @@ op|h|q|
 +-+-+r|
 |xyz|s|
 +-+-+-+
-|E|  F|
+|E|FGH|
 +-+-+-+
 |L|O|P|
 |M+-+-+