table: Require headers to be set at table creation.
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 25 Dec 2019 22:33:37 +0000 (22:33 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 29 Dec 2019 05:28:10 +0000 (05:28 +0000)
It used to be important for these to be adjustable, but no longer.

src/output/pivot-output.c
src/output/render.c
src/output/tab.c
src/output/tab.h
src/output/table.c
src/output/table.h
src/output/text-item.c
tests/output/render-test.c

index d805f42bb36e87bb77b4c0d15a4e9b289b18c719..aca56e7be405f8346875f186a2bb8236cd942f72 100644 (file)
@@ -310,8 +310,8 @@ pivot_table_submit_layer (const struct pivot_table *pt,
     [V] = pt->axes[PIVOT_AXIS_COLUMN].label_depth,
   };
   struct tab_table *table = tab_create (body[H] + stub[H],
-                                        body[V] + stub[V]);
-  tab_headers (table, stub[H], 0, stub[V], 0);
+                                        body[V] + stub[V],
+                                        stub[H], 0, stub[V], 0);
 
   for (size_t i = 0; i < PIVOT_N_AREAS; i++)
     table->styles[i] = area_style_override (table->container, &pt->areas[i],
index e6ce53164e2ba07e424adca94860529587a1c30c..94782882cee857cb496a2dae0476b21147c1075a 100644 (file)
@@ -1508,7 +1508,7 @@ add_footnote_page (struct render_pager *p, const struct table_item *item)
   if (!n_footnotes)
     return;
 
-  struct tab_table *t = tab_create (1, n_footnotes);
+  struct tab_table *t = tab_create (1, n_footnotes, 0, 0, 0, 0);
   for (size_t i = 0; i < n_footnotes; i++)
     {
       tab_text_format (t, 0, i, TAB_LEFT, "%s. %s",
@@ -1528,7 +1528,7 @@ add_text_page (struct render_pager *p, const struct table_item_text *t,
   if (!t)
     return;
 
-  struct tab_table *tab = tab_create (1, 1);
+  struct tab_table *tab = tab_create (1, 1, 0, 0, 0, 0);
   tab_text (tab, 0, 0, 0, t->content);
   for (size_t i = 0; i < t->n_footnotes; i++)
     tab_add_footnote (tab, 0, 0, t->footnotes[i]);
@@ -1544,7 +1544,7 @@ add_layers_page (struct render_pager *p,
   if (!layers)
     return;
 
-  struct tab_table *tab = tab_create (1, layers->n_layers);
+  struct tab_table *tab = tab_create (1, layers->n_layers, 0, 0, 0, 0);
   for (size_t i = 0; i < layers->n_layers; i++)
     {
       const struct table_item_layer *layer = &layers->layers[i];
index 0166b978083f6d85c73b558b4029c1791cdd85e0..defdf09add29bea05ee1b6f147889f19887a5b18 100644 (file)
@@ -64,17 +64,26 @@ struct tab_joined_cell
 };
 
 /* Creates and returns a new table with NC columns and NR rows and initially no
-   header rows or columns.  The table's cells are initially empty. */
+   header rows or columns.
+
+   Sets the number of header rows on each side of TABLE to HL on the
+   left, HR on the right, HT on the top, HB on the bottom.  Header rows
+   are repeated when a table is broken across multiple columns or
+   multiple pages.
+
+   The table's cells are initially empty. */
 struct tab_table *
-tab_create (int nc, int nr)
+tab_create (int nc, int nr, int hl, int hr, int ht, int hb)
 {
   struct tab_table *t;
 
   t = pool_create_container (struct tab_table, container);
   t->table.n[TABLE_HORZ] = nc;
   t->table.n[TABLE_VERT] = nr;
-  t->table.h[TABLE_HORZ][0] = t->table.h[TABLE_HORZ][1] = 0;
-  t->table.h[TABLE_VERT][0] = t->table.h[TABLE_VERT][1] = 0;
+  t->table.h[TABLE_HORZ][0] = hl;
+  t->table.h[TABLE_HORZ][1] = hr;
+  t->table.h[TABLE_VERT][0] = ht;
+  t->table.h[TABLE_VERT][1] = hb;
   t->table.ref_cnt = 1;
 
   t->cc = pool_calloc (t->container, nr * nc, sizeof *t->cc);
@@ -91,20 +100,6 @@ tab_create (int nc, int nr)
 
   return t;
 }
-
-
-/* Sets the number of header rows on each side of TABLE to L on the
-   left, R on the right, T on the top, B on the bottom.  Header rows
-   are repeated when a table is broken across multiple columns or
-   multiple pages. */
-void
-tab_headers (struct tab_table *table, int l, int r, int t, int b)
-{
-  table_set_hl (&table->table, l);
-  table_set_hr (&table->table, r);
-  table_set_ht (&table->table, t);
-  table_set_hb (&table->table, b);
-}
 \f
 /* Rules. */
 
index 3f99ac6d07cefe6ec538d1644433d0c1a75286f8..e931b8304a1269533c40dfb8d0a896fd9b5cfc4f 100644 (file)
@@ -81,19 +81,9 @@ static inline int tab_nr (const struct tab_table *table)
 static inline int tab_nc (const struct tab_table *table)
         { return table_nc (&table->table); }
 
-/* Number of left/right/top/bottom header columns/rows in TABLE. */
-static inline int tab_l (const struct tab_table *table)
-        { return table_hl (&table->table); }
-static inline int tab_r (const struct tab_table *table)
-        { return table_hr (&table->table); }
-static inline int tab_t (const struct tab_table *table)
-        { return table_ht (&table->table); }
-static inline int tab_b (const struct tab_table *table)
-        { return table_hb (&table->table); }
-
 /* Tables. */
-struct tab_table *tab_create (int nc, int nr);
-void tab_headers (struct tab_table *, int l, int r, int t, int b);
+struct tab_table *tab_create (int nc, int nr,
+                              int l, int r, int t, int b);
 
 /* Rules. */
 void tab_hline (struct tab_table *, int style, int x1, int x2, int y);
index 01e2acd11892c54f9878b5998b79da3fd4c47dc6..7b229eb6b8c2341639de59535326249e619c4109 100644 (file)
@@ -65,38 +65,6 @@ table_is_shared (const struct table *table)
 {
   return table->ref_cnt > 1;
 }
-
-/* Sets the number of left header columns in TABLE to HL. */
-void
-table_set_hl (struct table *table, int hl)
-{
-  assert (!table_is_shared (table));
-  table->h[TABLE_HORZ][0] = hl;
-}
-
-/* Sets the number of right header columns in TABLE to HR. */
-void
-table_set_hr (struct table *table, int hr)
-{
-  assert (!table_is_shared (table));
-  table->h[TABLE_HORZ][1] = hr;
-}
-
-/* Sets the number of top header rows in TABLE to HT. */
-void
-table_set_ht (struct table *table, int ht)
-{
-  assert (!table_is_shared (table));
-  table->h[TABLE_VERT][0] = ht;
-}
-
-/* Sets the number of top header rows in TABLE to HB. */
-void
-table_set_hb (struct table *table, int hb)
-{
-  assert (!table_is_shared (table));
-  table->h[TABLE_VERT][1] = hb;
-}
 \f
 struct area_style *
 area_style_clone (struct pool *pool, const struct area_style *old)
@@ -271,7 +239,7 @@ table_collect_footnotes (const struct table_item *item,
 struct table *
 table_from_string (const char *text)
 {
-  struct tab_table *t = tab_create (1, 1);
+  struct tab_table *t = tab_create (1, 1, 0, 0, 0, 0);
   tab_text (t, 0, 0, TAB_LEFT, text);
   return &t->table;
 }
index aa1edc107c307165399e46cbe3404aa6fb898067..6caec33ff74306766b406e502ceb1629ff284edc 100644 (file)
@@ -254,12 +254,6 @@ static inline int table_ht (const struct table *t)
         { return t->h[TABLE_VERT][0]; }
 static inline int table_hb (const struct table *t)
         { return t->h[TABLE_VERT][1]; }
-
-/* Set headers. */
-void table_set_hl (struct table *, int hl);
-void table_set_hr (struct table *, int hr);
-void table_set_ht (struct table *, int ht);
-void table_set_hb (struct table *, int hb);
 \f
 /* Table classes. */
 
index 7ef12de247daef225141897c6375cf75312328c4..20b424732b605af3093b9d80ec62ff4674248d95 100644 (file)
@@ -119,7 +119,7 @@ text_item_submit (struct text_item *item)
 struct table_item *
 text_item_to_table_item (struct text_item *text_item)
 {
-  struct tab_table *tab = tab_create (1, 1);
+  struct tab_table *tab = tab_create (1, 1, 0, 0, 0, 0);
 
   struct area_style *style = pool_alloc (tab->container, sizeof *style);
   *style = (struct area_style) { AREA_STYLE_INITIALIZER__,
index 4c559a53d970d358bffa16ddbe1084a8f9472f77..961ff59a86142f111853a40f8c56cf68b646d60f 100644 (file)
@@ -381,8 +381,7 @@ read_table (FILE *stream)
   ht = n_input >= 5 ? input[4] : 0;
   hb = n_input >= 6 ? input[5] : 0;
 
-  tab = tab_create (nc, nr);
-  tab_headers (tab, hl, hr, ht, hb);
+  tab = tab_create (nc, nr, hl, hr, ht, hb);
   for (r = 0; r < nr; r++)
     for (c = 0; c < nc; c++)
       if (tab_cell_is_empty (tab, c, r))