output: Introduce group_item in place of TEXT_ITEM_COMMAND_OPEN and CLOSE.
[pspp] / src / output / cairo.c
index 0176d3caa22b3ace45c83fd349e14e15cf4aaee6..4922590448c53326d9dccbb5b1065e3092dd6106 100644 (file)
@@ -87,6 +87,10 @@ px_to_xr (int x)
   return x * (PANGO_SCALE * 72 / 96);
 }
 
+/* Dimensions for drawing lines in tables. */
+#define XR_LINE_WIDTH (XR_POINT / 2) /* Width of an ordinary line. */
+#define XR_LINE_SPACE XR_POINT       /* Space between double lines. */
+
 /* Output types. */
 enum xr_output_type
   {
@@ -172,7 +176,7 @@ static void xr_measure_cell_width (void *, const struct table_cell *,
                                    int *min, int *max);
 static int xr_measure_cell_height (void *, const struct table_cell *,
                                    int width);
-static void xr_draw_cell (void *, const struct table_cell *,
+static void xr_draw_cell (void *, const struct table_cell *, int color_idx,
                           int bb[TABLE_N_AXES][2],
                           int spill[TABLE_N_AXES][2],
                           int clip[TABLE_N_AXES][2]);
@@ -309,8 +313,6 @@ apply_options (struct xr_driver *xr, struct string_map *o)
   xr->fonts[XR_FONT_EMPHASIS].desc = parse_font_option (
     d, o, "emph-font", "sans serif", font_size, false, true);
 
-  xr->line_space = XR_POINT;
-  xr->line_width = XR_POINT / 2;
   xr->page_number = 0;
 
   parse_color (d, o, "background-color", "#FFFFFFFFFFFF", &xr->bg);
@@ -373,7 +375,7 @@ xr_set_cairo (struct xr_driver *xr, cairo_t *cairo)
 
   xr->cairo = cairo;
 
-  cairo_set_line_width (xr->cairo, xr_to_pt (xr->line_width));
+  cairo_set_line_width (xr->cairo, xr_to_pt (XR_LINE_WIDTH));
 
   xr->char_width = 0;
   xr->char_height = 0;
@@ -405,8 +407,8 @@ xr_set_cairo (struct xr_driver *xr, cairo_t *cairo)
       xr->params->font_size[H] = xr->char_width;
       xr->params->font_size[V] = xr->char_height;
 
-      int lw = xr->line_width;
-      int ls = xr->line_space;
+      int lw = XR_LINE_WIDTH;
+      int ls = XR_LINE_SPACE;
       for (i = 0; i < TABLE_N_AXES; i++)
         {
           xr->params->line_widths[i][RENDER_LINE_NONE] = 0;
@@ -667,9 +669,9 @@ dump_line (struct xr_driver *xr, int x0, int y0, int x1, int y1, int style,
                         color->r / 255.0, color->g / 255.0, color->b / 255.0);
   cairo_set_line_width (
     xr->cairo,
-    xr_to_pt (style == RENDER_LINE_THICK ? xr->line_width * 2
-              : style == RENDER_LINE_THIN ? xr->line_width / 2
-              : xr->line_width));
+    xr_to_pt (style == RENDER_LINE_THICK ? XR_LINE_WIDTH * 2
+              : style == RENDER_LINE_THIN ? XR_LINE_WIDTH / 2
+              : XR_LINE_WIDTH));
   cairo_move_to (xr->cairo, xr_to_pt (x0 + xr->x), xr_to_pt (y0 + xr->y));
   cairo_line_to (xr->cairo, xr_to_pt (x1 + xr->x), xr_to_pt (y1 + xr->y));
   cairo_stroke (xr->cairo);
@@ -679,7 +681,7 @@ static void UNUSED
 dump_rectangle (struct xr_driver *xr, int x0, int y0, int x1, int y1)
 {
   cairo_new_path (xr->cairo);
-  cairo_set_line_width (xr->cairo, xr_to_pt (xr->line_width));
+  cairo_set_line_width (xr->cairo, xr_to_pt (XR_LINE_WIDTH));
   cairo_move_to (xr->cairo, xr_to_pt (x0 + xr->x), xr_to_pt (y0 + xr->y));
   cairo_line_to (xr->cairo, xr_to_pt (x1 + xr->x), xr_to_pt (y0 + xr->y));
   cairo_line_to (xr->cairo, xr_to_pt (x1 + xr->x), xr_to_pt (y1 + xr->y));
@@ -692,7 +694,7 @@ static void
 fill_rectangle (struct xr_driver *xr, int x0, int y0, int x1, int y1)
 {
   cairo_new_path (xr->cairo);
-  cairo_set_line_width (xr->cairo, xr_to_pt (xr->line_width));
+  cairo_set_line_width (xr->cairo, xr_to_pt (XR_LINE_WIDTH));
   cairo_rectangle (xr->cairo,
                    xr_to_pt (x0 + xr->x), xr_to_pt (y0 + xr->y),
                    xr_to_pt (x1 - x0), xr_to_pt (y1 - y0));
@@ -798,7 +800,7 @@ xr_draw_line (void *xr_, int bb[TABLE_N_AXES][2],
   struct xr_driver *xr = xr_;
 
   /* Offset from center of each line in a pair of double lines. */
-  int double_line_ofs = (xr->line_space + xr->line_width) / 2;
+  int double_line_ofs = (XR_LINE_SPACE + XR_LINE_WIDTH) / 2;
 
   /* Are the lines along each axis single or double?
      (It doesn't make sense to have different kinds of line on the
@@ -919,7 +921,7 @@ xr_measure_cell_height (void *xr_, const struct table_cell *cell, int width)
 static void xr_clip (struct xr_driver *, int clip[TABLE_N_AXES][2]);
 
 static void
-xr_draw_cell (void *xr_, const struct table_cell *cell,
+xr_draw_cell (void *xr_, const struct table_cell *cell, int color_idx,
               int bb[TABLE_N_AXES][2],
               int spill[TABLE_N_AXES][2],
               int clip[TABLE_N_AXES][2])
@@ -941,9 +943,9 @@ xr_draw_cell (void *xr_, const struct table_cell *cell,
     }
   xr_clip (xr, bg_clip);
   cairo_set_source_rgb (xr->cairo,
-                        cell->style->bg.r / 255.,
-                        cell->style->bg.g / 255.,
-                        cell->style->bg.b / 255.);
+                        cell->style->bg[color_idx].r / 255.,
+                        cell->style->bg[color_idx].g / 255.,
+                        cell->style->bg[color_idx].b / 255.);
   fill_rectangle (xr,
                   bb[H][0] - spill[H][0],
                   bb[V][0] - spill[V][0],
@@ -953,9 +955,9 @@ xr_draw_cell (void *xr_, const struct table_cell *cell,
 
   cairo_save (xr->cairo);
   cairo_set_source_rgb (xr->cairo,
-                        cell->style->fg.r / 255.,
-                        cell->style->fg.g / 255.,
-                        cell->style->fg.b / 255.);
+                        cell->style->fg[color_idx].r / 255.,
+                        cell->style->fg[color_idx].g / 255.,
+                        cell->style->fg[color_idx].b / 255.);
 
   for (int axis = 0; axis < TABLE_N_AXES; axis++)
     {
@@ -1354,8 +1356,7 @@ xr_rendering_create (struct xr_driver *xr, const struct output_item *item,
   else if (is_message_item (item))
     {
       const struct message_item *message_item = to_message_item (item);
-      const struct msg *msg = message_item_get_msg (message_item);
-      char *s = msg_to_string (msg, NULL);
+      char *s = msg_to_string (message_item_get_msg (message_item));
       r = xr_rendering_create_text (xr, s, cr);
       free (s);
     }
@@ -1660,21 +1661,10 @@ static struct xr_render_fsm *
 xr_render_text (struct xr_driver *xr, const struct text_item *text_item)
 {
   enum text_item_type type = text_item_get_type (text_item);
-  const char *text = text_item_get_text (text_item);
 
   switch (type)
     {
-    case TEXT_ITEM_TITLE:
-      free (xr->title);
-      xr->title = xstrdup (text);
-      break;
-
-    case TEXT_ITEM_SUBTITLE:
-      free (xr->subtitle);
-      xr->subtitle = xstrdup (text);
-      break;
-
-    case TEXT_ITEM_COMMAND_CLOSE:
+    case TEXT_ITEM_PAGE_TITLE:
       break;
 
     case TEXT_ITEM_BLANK_LINE:
@@ -1698,8 +1688,7 @@ static struct xr_render_fsm *
 xr_render_message (struct xr_driver *xr,
                    const struct message_item *message_item)
 {
-  const struct msg *msg = message_item_get_msg (message_item);
-  char *s = msg_to_string (msg, message_item->command_name);
+  char *s = msg_to_string (message_item_get_msg (message_item));
   struct text_item *item = text_item_create (TEXT_ITEM_PARAGRAPH, s);
   free (s);
   struct xr_render_fsm *fsm = xr_create_text_renderer (xr, item);