output: Reimplement table_from_string in terms of tab.
[pspp] / src / output / cairo.c
index 1dc8fe09668b1969ecf2a4b85f7b8dc1c20d7192..4794fe25e1ec8b0a8264e3ad795b9bb2b6d4c7fb 100644 (file)
@@ -44,7 +44,6 @@
 #include "output/options.h"
 #include "output/page-setup-item.h"
 #include "output/render.h"
-#include "output/tab.h"
 #include "output/table-item.h"
 #include "output/table.h"
 #include "output/text-item.h"
@@ -832,13 +831,20 @@ xr_layout_cell (struct xr_driver *, const struct table_cell *,
                 int bb[TABLE_N_AXES][2], int clip[TABLE_N_AXES][2],
                 int *width, int *height, int *brk);
 
+static void
+set_source_rgba (cairo_t *cairo, const struct cell_color *color)
+{
+  cairo_set_source_rgba (cairo,
+                         color->r / 255., color->g / 255., color->b / 255.,
+                         color->alpha / 255.);
+}
+
 static void
 dump_line (struct xr_driver *xr, int x0, int y0, int x1, int y1, int style,
            const struct cell_color *color)
 {
   cairo_new_path (xr->cairo);
-  cairo_set_source_rgb (xr->cairo,
-                        color->r / 255.0, color->g / 255.0, color->b / 255.0);
+  set_source_rgba (xr->cairo, color);
   cairo_set_line_width (
     xr->cairo,
     xr_to_pt (style == RENDER_LINE_THICK ? XR_LINE_WIDTH * 2
@@ -1115,10 +1121,7 @@ xr_draw_cell (void *xr_, const struct table_cell *cell, int color_idx,
         bg_clip[axis][1] += spill[axis][1];
     }
   xr_clip (xr, bg_clip);
-  cairo_set_source_rgb (xr->cairo,
-                        cell->style->font_style.bg[color_idx].r / 255.,
-                        cell->style->font_style.bg[color_idx].g / 255.,
-                        cell->style->font_style.bg[color_idx].b / 255.);
+  set_source_rgba (xr->cairo, &cell->style->font_style.bg[color_idx]);
   fill_rectangle (xr,
                   bb[H][0] - spill[H][0],
                   bb[V][0] - spill[V][0],
@@ -1127,10 +1130,7 @@ xr_draw_cell (void *xr_, const struct table_cell *cell, int color_idx,
   cairo_restore (xr->cairo);
 
   cairo_save (xr->cairo);
-  cairo_set_source_rgb (xr->cairo,
-                        cell->style->font_style.fg[color_idx].r / 255.,
-                        cell->style->font_style.fg[color_idx].g / 255.,
-                        cell->style->font_style.fg[color_idx].b / 255.);
+  set_source_rgba (xr->cairo, &cell->style->font_style.fg[color_idx]);
 
   for (int axis = 0; axis < TABLE_N_AXES; axis++)
     {
@@ -1232,7 +1232,6 @@ xr_layout_cell_text (struct xr_driver *xr, const struct table_cell *cell,
   int R = options & TAB_ROTATE ? 0 : 1;
 
   struct xr_font *font = (options & TAB_FIX ? &xr->fonts[XR_FONT_FIXED]
-                          : options & TAB_EMPH ? &xr->fonts[XR_FONT_EMPHASIS]
                           : &xr->fonts[XR_FONT_PROPORTIONAL]);
   struct xr_font local_font;
   if (font_style->typeface)
@@ -1586,8 +1585,7 @@ xr_rendering_create_text (struct xr_driver *xr, const char *text, cairo_t *cr)
   struct table_item *table_item;
   struct xr_rendering *r;
 
-  table_item = table_item_create (table_from_string (TABLE_HALIGN_LEFT, text),
-                                  NULL, NULL);
+  table_item = table_item_create (table_from_string (text), NULL, NULL);
   r = xr_rendering_create (xr, &table_item->output_item, cr);
   table_item_unref (table_item);
 
@@ -1649,18 +1647,25 @@ xr_rendering_destroy (struct xr_rendering *r)
 }
 
 void
-xr_rendering_measure (struct xr_rendering *r, int *w, int *h)
+xr_rendering_measure (struct xr_rendering *r, int *wp, int *hp)
 {
+  int w, h;
+
   if (is_table_item (r->item))
     {
-      *w = render_pager_get_size (r->p, H) / XR_POINT;
-      *h = render_pager_get_size (r->p, V) / XR_POINT;
+      w = render_pager_get_size (r->p, H) / XR_POINT;
+      h = render_pager_get_size (r->p, V) / XR_POINT;
     }
   else
     {
-      *w = CHART_WIDTH;
-      *h = CHART_HEIGHT;
+      w = CHART_WIDTH;
+      h = CHART_HEIGHT;
     }
+
+  if (wp)
+    *wp = w;
+  if (hp)
+    *hp = h;
 }
 
 static void xr_draw_chart (const struct chart_item *, cairo_t *,