Add a TeX driver
[pspp] / src / output / render.c
index 636568f4eedd6bcf0f53b78b6b8cb8932e75fe33..06360eeecb32eaeacd652407cc6877a277a01697 100644 (file)
@@ -27,7 +27,6 @@
 #include "libpspp/hmap.h"
 #include "libpspp/pool.h"
 #include "output/render.h"
-#include "output/tab.h"
 #include "output/table-item.h"
 #include "output/table.h"
 
@@ -463,17 +462,17 @@ rule_to_render_type (unsigned char type)
 {
   switch (type)
     {
-    case TAL_NONE:
+    case TABLE_STROKE_NONE:
       return RENDER_LINE_NONE;
-    case TAL_SOLID:
+    case TABLE_STROKE_SOLID:
       return RENDER_LINE_SINGLE;
-    case TAL_DASHED:
+    case TABLE_STROKE_DASHED:
       return RENDER_LINE_DASHED;
-    case TAL_THICK:
+    case TABLE_STROKE_THICK:
       return RENDER_LINE_THICK;
-    case TAL_THIN:
+    case TABLE_STROKE_THIN:
       return RENDER_LINE_THIN;
-    case TAL_DOUBLE:
+    case TABLE_STROKE_DOUBLE:
       return RENDER_LINE_DOUBLE;
     default:
       NOT_REACHED ();
@@ -497,15 +496,15 @@ measure_rule (const struct render_params *params, const struct table *table,
   for (d[b] = 0; d[b] < table->n[b]; d[b]++)
     rules |= 1u << table_get_rule (table, a, d[H], d[V], &color);
 
-  /* Turn off TAL_NONE because it has width 0 and we needn't bother.  However,
-     if the device doesn't support margins, make sure that there is at least a
-     small gap between cells (but we don't need any at the left or right edge
-     of the table). */
-  if (rules & (1u << TAL_NONE))
+  /* Turn off TABLE_STROKE_NONE because it has width 0 and we needn't bother.
+     However, if the device doesn't support margins, make sure that there is at
+     least a small gap between cells (but we don't need any at the left or
+     right edge of the table). */
+  if (rules & (1u << TABLE_STROKE_NONE))
     {
-      rules &= ~(1u << TAL_NONE);
+      rules &= ~(1u << TABLE_STROKE_NONE);
       if (z > 0 && z < table->n[a] && !params->supports_margins && a == H)
-        rules |= 1u << TAL_SOLID;
+        rules |= 1u << TABLE_STROKE_SOLID;
     }
 
   /* Calculate maximum width of the rules that are present. */
@@ -727,7 +726,7 @@ render_page_create (const struct render_params *params, struct table *table,
   for (int i = 0; i < 2; i++)
     columns[i] = xzalloc (nc * sizeof *columns[i]);
   for (int y = 0; y < nr; y++)
-    for (int x = 0; x < nc; )
+    for (int x = 0; x < nc;)
       {
         struct table_cell cell;
 
@@ -745,7 +744,6 @@ render_page_create (const struct render_params *params, struct table *table,
               }
           }
         x = cell.d[H][1];
-        table_cell_free (&cell);
       }
 
   /* Distribute widths of spanned columns. */
@@ -753,7 +751,7 @@ render_page_create (const struct render_params *params, struct table *table,
     for (int x = 0; x < nc; x++)
       columns[i][x].width = columns[i][x].unspanned;
   for (int y = 0; y < nr; y++)
-    for (int x = 0; x < nc; )
+    for (int x = 0; x < nc;)
       {
         struct table_cell cell;
 
@@ -768,7 +766,6 @@ render_page_create (const struct render_params *params, struct table *table,
                                         rules[H], table_cell_colspan (&cell));
           }
         x = cell.d[H][1];
-        table_cell_free (&cell);
       }
   if (min_width > 0)
     for (int i = 0; i < 2; i++)
@@ -812,7 +809,7 @@ render_page_create (const struct render_params *params, struct table *table,
   /* Calculate heights of cells that do not span multiple rows. */
   struct render_row *rows = xzalloc (nr * sizeof *rows);
   for (int y = 0; y < nr; y++)
-    for (int x = 0; x < nc; )
+    for (int x = 0; x < nc;)
       {
         struct render_row *r = &rows[y];
         struct table_cell cell;
@@ -834,14 +831,13 @@ render_page_create (const struct render_params *params, struct table *table,
               set_join_crossings (page, H, &cell, rules[H]);
           }
         x = cell.d[H][1];
-        table_cell_free (&cell);
       }
   for (int i = 0; i < 2; i++)
     free (columns[i]);
 
   /* Distribute heights of spanned rows. */
   for (int y = 0; y < nr; y++)
-    for (int x = 0; x < nc; )
+    for (int x = 0; x < nc;)
       {
         struct table_cell cell;
 
@@ -854,7 +850,6 @@ render_page_create (const struct render_params *params, struct table *table,
                                       table_cell_rowspan (&cell));
           }
         x = cell.d[H][1];
-        table_cell_free (&cell);
       }
 
   /* Decide final row heights. */
@@ -978,7 +973,7 @@ get_rule (const struct render_page *page, enum table_axis axis,
     {
       d[a] = d2;
       int r2 = table_get_rule (page->table, axis, d[H], d[V], color);
-      r = table_rule_combine (r, r2);
+      r = table_stroke_combine (r, r2);
     }
   return rule_to_render_type (r);
 }
@@ -997,10 +992,10 @@ render_direction_rtl (void)
      this string with "output-direction-rtl".  Otherwise either leave it
      untranslated or copy it verbatim. */
   const char *dir = _("output-direction-ltr");
-  if ( 0 == strcmp ("output-direction-rtl", dir))
+  if (0 == strcmp ("output-direction-rtl", dir))
     return true;
 
-  if ( 0 != strcmp ("output-direction-ltr", dir))
+  if (0 != strcmp ("output-direction-ltr", dir))
     fprintf (stderr, "This localisation has been incorrectly translated.  "
              "Complain to the translator.\n");
 
@@ -1139,7 +1134,7 @@ render_page_draw_cells (const struct render_page *page,
                         int ofs[TABLE_N_AXES], int bb[TABLE_N_AXES][2])
 {
   for (int y = bb[V][0]; y < bb[V][1]; y++)
-    for (int x = bb[H][0]; x < bb[H][1]; )
+    for (int x = bb[H][0]; x < bb[H][1];)
       if (!is_rule (x) && !is_rule (y))
         {
           struct table_cell cell;
@@ -1148,7 +1143,6 @@ render_page_draw_cells (const struct render_page *page,
           if (y / 2 == bb[V][0] / 2 || y / 2 == cell.d[V][0])
             render_cell (page, ofs, &cell);
           x = rule_ofs (cell.d[H][1]);
-          table_cell_free (&cell);
         }
       else
         x++;
@@ -1376,7 +1370,7 @@ render_break_next (struct render_break *b, int size)
                  number of pixels available, which might look bad e.g. because
                  it breaks in the middle of a line of text. */
               if (axis == TABLE_VERT && page->params->adjust_break)
-                for (int x = 0; x < page->n[H]; )
+                for (int x = 0; x < page->n[H];)
                   {
                     struct table_cell cell;
 
@@ -1385,7 +1379,6 @@ render_break_next (struct render_break *b, int size)
                     int better_pixel = page->params->adjust_break (
                       page->params->aux, &cell, w, pixel);
                     x = cell.d[H][1];
-                    table_cell_free (&cell);
 
                     if (better_pixel < pixel)
                       {
@@ -1514,19 +1507,14 @@ add_footnote_page (struct render_pager *p, const struct table_item *item)
   if (!n_footnotes)
     return;
 
-  struct tab_table *t = tab_create (2, n_footnotes);
+  struct table *t = table_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.", f[i]->marker);
-      tab_text (t, 1, i, TAB_LEFT, f[i]->content);
-      if (f[i]->style)
-        {
-          tab_add_style (t, 0, i, f[i]->style);
-          tab_add_style (t, 1, i, f[i]->style);
-        }
+      table_text_format (t, 0, i, 0, "%s. %s", f[i]->marker, f[i]->content);
+      table_add_style (t, 0, i, f[i]->style);
     }
-  render_pager_add_table (p, &t->table, 0);
+  render_pager_add_table (p, t, 0);
 
   free (f);
 }
@@ -1538,13 +1526,33 @@ add_text_page (struct render_pager *p, const struct table_item_text *t,
   if (!t)
     return;
 
-  struct tab_table *tab = tab_create (1, 1);
-  tab_text (tab, 0, 0, 0, t->content);
+  struct table *tab = table_create (1, 1, 0, 0, 0, 0);
+  table_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]);
+    table_add_footnote (tab, 0, 0, t->footnotes[i]);
   if (t->style)
     tab->styles[0] = area_style_clone (tab->container, t->style);
-  render_pager_add_table (p, &tab->table, min_width);
+  render_pager_add_table (p, tab, min_width);
+}
+
+static void
+add_layers_page (struct render_pager *p,
+                 const struct table_item_layers *layers, int min_width)
+{
+  if (!layers)
+    return;
+
+  struct table *tab = table_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];
+      table_text (tab, 0, i, 0, layer->content);
+      for (size_t j = 0; j < layer->n_footnotes; j++)
+        table_add_footnote (tab, 0, i, layer->footnotes[j]);
+    }
+  if (layers->style)
+    tab->styles[0] = area_style_clone (tab->container, layers->style);
+  render_pager_add_table (p, tab, min_width);
 }
 
 /* Creates and returns a new render_pager for rendering TABLE_ITEM on the
@@ -1570,7 +1578,7 @@ render_pager_create (const struct render_params *params,
   add_text_page (p, table_item_get_title (table_item), title_width);
 
   /* Layers. */
-  add_text_page (p, table_item_get_layers (table_item), title_width);
+  add_layers_page (p, table_item_get_layers (table_item), title_width);
 
   /* Body. */
   render_pager_add_table (p, table_ref (table_item_get_table (table_item)), 0);
@@ -1864,7 +1872,7 @@ render_page_select (const struct render_page *page, enum table_axis axis,
   };
 
   if (!page->h[a][0] || z0 > page->h[a][0] || p0)
-    for (int z = 0; z < page->n[b]; )
+    for (int z = 0; z < page->n[b];)
       {
         int d[TABLE_N_AXES];
         d[a] = z0;
@@ -1896,11 +1904,10 @@ render_page_select (const struct render_page *page, enum table_axis axis,
               }
           }
         z = cell.d[b][1];
-        table_cell_free (&cell);
       }
 
   if (!page->h[a][1] || z1 < page->n[a] - page->h[a][1] || p1)
-    for (int z = 0; z < page->n[b]; )
+    for (int z = 0; z < page->n[b];)
       {
         int d[TABLE_N_AXES];
         d[a] = z1 - 1;
@@ -1916,7 +1923,6 @@ render_page_select (const struct render_page *page, enum table_axis axis,
                                                    cell_ofs (cell.d[a][1]));
           }
         z = cell.d[b][1];
-        table_cell_free (&cell);
       }
 
   /* Copy overflows from PAGE into subpage. */
@@ -1929,7 +1935,6 @@ render_page_select (const struct render_page *page, enum table_axis axis,
       if (cell.d[a][1] > z0 && cell.d[a][0] < z1
           && find_overflow_for_cell (&s, &cell) == NULL)
         insert_overflow (&s, &cell);
-      table_cell_free (&cell);
     }
 
   return subpage;