table-provider: Remove "const" from struct table_cell members.
[pspp] / src / output / tex.c
index 8fad5623114b1e65eb4fc8a4f909a673d3f5239e..15540cd1e28a411c617a90a48e4ff1cae60e3b33 100644 (file)
@@ -36,7 +36,9 @@
 #include "libpspp/message.h"
 #include "libpspp/temp-file.h"
 #include "libpspp/version.h"
-#include "output/cairo.h"
+#ifdef HAVE_CAIRO
+#include "output/cairo-chart.h"
+#endif
 #include "output/chart-item.h"
 #include "output/driver-provider.h"
 #include "output/message-item.h"
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 
+/* This file uses TABLE_HORZ and TABLE_VERT enough to warrant abbreviating. */
+#define H TABLE_HORZ
+#define V TABLE_VERT
+
 /* The desired maximum line length in the TeX file.  */
 #define TEX_LINE_MAX 80
 
@@ -66,6 +72,7 @@ struct tex_driver
     struct output_driver driver;
     /* A hash table containing any Tex macros which need to be emitted.  */
     struct hmap macros;
+    bool require_graphics;
 #ifdef HAVE_CAIRO
     struct cell_color fg;
     struct cell_color bg;
@@ -132,8 +139,8 @@ tex_create (struct file_handle *fh, enum settings_output_devices device_type,
                                                       fh_get_file_name (fh)));
   tex->chart_cnt = 1;
 #ifdef HAVE_CAIRO
-  parse_color (d, o, "background-color", "#FFFFFFFFFFFF", &tex->bg);
-  parse_color (d, o, "foreground-color", "#000000000000", &tex->fg);
+  tex->bg = parse_color (opt (d, o, "background-color", "#FFFFFFFFFFFF"));
+  tex->fg = parse_color (opt (d, o, "foreground-color", "#000000000000"));
 #endif
 
   tex->file = fn_open (tex->handle, "w");
@@ -215,8 +222,6 @@ tex_destroy (struct output_driver *driver)
   shipout (&tex->preamble_list, "%%%% Define the horizontal space between table columns\n");
   shipout (&tex->preamble_list, "\\def\\psppcolumnspace{1mm}\n\n");
 
-  shipout (&tex->preamble_list, "\\input graphicx\n\n");
-
   char *ln = get_language ();
   if (ln)
     shipout (&tex->preamble_list, "%%%% Language is \"%s\"\n", ln);
@@ -260,6 +265,9 @@ tex_destroy (struct output_driver *driver)
     }
   hmap_destroy (&tex->macros);
 
+  if (tex->require_graphics)
+    shipout (&tex->preamble_list, "\\input graphicx\n\n");
+
   post_process_tokens (tex->file, &tex->preamble_list);
 
   shipout (&tex->token_list, "\n\\bye\n");
@@ -323,10 +331,11 @@ tex_submit (struct output_driver *driver,
                                            &tex->bg);
       if (file_name != NULL)
         {
-         const char *title = chart_item_get_title (chart_item);
+         //const char *title = chart_item_get_title (chart_item);
           //          printf ("The chart title is %s\n", title);
 
           shipout (&tex->token_list, "\\includegraphics{%s}\n", file_name);
+          tex->require_graphics = true;
           free (file_name);
         }
     }
@@ -350,10 +359,6 @@ tex_submit (struct output_driver *driver,
           shipout (&tex->token_list, "}\\par\n\n");
           break;
 
-        case TEXT_ITEM_EJECT_PAGE:
-          /* Nothing to do. */
-          break;
-
         case TEXT_ITEM_SYNTAX:
           /* So far as I'm aware, this can never happen.  */
         default:
@@ -373,8 +378,8 @@ tex_submit (struct output_driver *driver,
 
 static void
 tex_put_footnote_markers (struct tex_driver *tex,
-                           const struct footnote **footnotes,
-                           size_t n_footnotes)
+                          struct footnote **footnotes,
+                          size_t n_footnotes)
 {
   if (n_footnotes > 0)
     shipout (&tex->token_list, "$^{");
@@ -413,7 +418,7 @@ tex_output_table (struct tex_driver *tex, const struct table_item *item)
       tex_escape_string (tex, caption->content, false);
       shipout (&tex->token_list, "}\n\n");
     }
-  const struct footnote **f;
+  struct footnote **f;
   size_t n_footnotes = table_collect_footnotes (item, &f);
 
   const struct table_item_text *title = table_item_get_title (item);
@@ -434,11 +439,11 @@ tex_output_table (struct tex_driver *tex, const struct table_item *item)
   shipout (&tex->token_list, "\\offinterlineskip\\halign{\\strut%%\n");
 
   /* Generate the preamble */
-  for (int x = 0; x < table_nc (t); ++x)
+  for (int x = 0; x < t->n[H]; ++x)
     {
-      shipout (&tex->token_list, "{\\vbox{\\cell{%d}#}}", table_nc (t));
+      shipout (&tex->token_list, "{\\vbox{\\cell{%d}#}}", t->n[H]);
 
-      if (x < table_nc (t) - 1)
+      if (x < t->n[H] - 1)
         {
           shipout (&tex->token_list, "\\hskip\\psppcolumnspace\\hfil");
           shipout (&tex->token_list, "&\\vrule\n");
@@ -448,13 +453,13 @@ tex_output_table (struct tex_driver *tex, const struct table_item *item)
     }
 
   /* Emit the row data */
-  for (int y = 0; y < table_nr (t); y++)
+  for (int y = 0; y < t->n[V]; y++)
     {
-      bool is_column_header = (y < table_ht (t)
-                               || y >= table_nr (t) - table_hb (t));
+      enum { H = TABLE_HORZ, V = TABLE_VERT };
+      bool is_column_header = y < t->h[V][0] || y >= t->n[V] - t->h[V][1];
       int prev_x = -1;
       int skipped = 0;
-      for (int x = 0; x < table_nc (t);)
+      for (int x = 0; x < t->n[H];)
         {
           struct table_cell cell;
 
@@ -471,11 +476,10 @@ tex_output_table (struct tex_driver *tex, const struct table_item *item)
           if (x != cell.d[TABLE_HORZ][0] || y != cell.d[TABLE_VERT][0])
             goto next_1;
 
-          /* bool is_header = (y < table_ht (t) */
-          /*                   || y >= table_nr (t) - table_hb (t) */
-          /*                   || x < table_hl (t) */
-          /*                   || x >= table_nc (t) - table_hr (t)); */
-
+          /* bool is_header = (y < t->h[V][0] */
+          /*                   || y >= t->n[V] - t->h[V][1] */
+          /*                   || x < t->h[H][0] */
+          /*                   || x >= t->n[H] - t->h[H][1]); */
 
           enum table_halign halign =
             table_halign_interpret (cell.style->cell_style.halign,