work toward getting rid of struct table in table_item
[pspp] / src / output / cairo-fsm.c
index 708bedec03756fc379a193151066c31e2197104e..58bbf230d5aada148969733bd73eefe4ebdb66e5 100644 (file)
@@ -115,12 +115,27 @@ xr_fsm_style_equals (const struct xr_fsm_style *a,
   return true;
 }
 \f
+/* Renders a single output_item to an output device in one of two ways:
+
+   - 'print == true': Broken across multiple pages if necessary.
+
+   - 'print == false': In a single region that the user may scroll around if
+     needed.
+
+   Normally 'output_item' corresponds to a single rendering.  There is a
+   special case when 'print == true' and 'output_item' is a table_item with
+   multiple layers and 'item->pt->table_look->print_all_layers == true'.  In
+   that case, each layer is rendered separately from the FSM's internal point
+   of view; from the client's point of view, it is all one operation.
+*/
 struct xr_fsm
   {
     struct xr_fsm_style *style;
     struct output_item *item;
+    bool print;
 
     /* Table items only. */
+    size_t *layer_indexes;
     struct render_params rp;
     struct render_pager *p;
     cairo_t *cairo;             /* XXX should this be here?! */
@@ -957,9 +972,10 @@ xr_layout_cell (struct xr_fsm *xr, const struct table_cell *cell,
 #define CHART_WIDTH 500
 #define CHART_HEIGHT 375
 
-struct xr_fsm *
+static struct xr_fsm *
 xr_fsm_create (const struct output_item *item_,
-               const struct xr_fsm_style *style, cairo_t *cr)
+               const struct xr_fsm_style *style, cairo_t *cr,
+               bool print)
 {
   if (is_page_setup_item (item_)
       || is_group_open_item (item_)
@@ -1001,6 +1017,14 @@ xr_fsm_create (const struct output_item *item_,
           || is_chart_item (item)
           || is_page_eject_item (item));
 
+  size_t *layer_indexes = NULL;
+  if (is_table_item (item))
+    {
+      layer_indexes = pivot_table_next_layer (table_item->pt, NULL, print);
+      if (!layer_indexes)
+        return NULL;
+    }
+
   static const struct render_ops xrr_render_ops = {
     .measure_cell_width = xrr_measure_cell_width,
     .measure_cell_height = xrr_measure_cell_height,
@@ -1021,10 +1045,16 @@ xr_fsm_create (const struct output_item *item_,
       [RENDER_LINE_DOUBLE] = 2 * LW + LS,
     };
 
+  size_t *layer_indexes = NULL;
+  if (is_table_item (item)
+  pivot_table_next_display_layer (
+
   struct xr_fsm *fsm = xmalloc (sizeof *fsm);
   *fsm = (struct xr_fsm) {
     .style = xr_fsm_style_ref (style),
     .item = item,
+    .print = print,
+    .layer_indexes = layer_indexes,
     .rp = {
       .ops = &xrr_render_ops,
       .aux = fsm,
@@ -1036,13 +1066,6 @@ xr_fsm_create (const struct output_item *item_,
     }
   };
 
-  if (is_table_item (item))
-    {
-      fsm->cairo = cr;
-      fsm->p = render_pager_create (&fsm->rp, to_table_item (item));
-      fsm->cairo = NULL;
-    }
-
   for (int i = 0; i < XR_N_FONTS; i++)
     {
       PangoContext *context = pango_cairo_create_context (cr);
@@ -1065,6 +1088,15 @@ xr_fsm_create (const struct output_item *item_,
       g_object_unref (G_OBJECT (layout));
     }
 
+  if (is_table_item (item))
+    {
+      struct table_item *table_item = to_table_item (item);
+
+      fsm->cairo = cr;
+      fsm->p = render_pager_create (&fsm->rp, table_item);
+      fsm->cairo = NULL;
+    }
+
   return fsm;
 }