output: Use Cairo and Pango to draw charts, instead of libplot.
[pspp-builds.git] / src / output / cairo.c
index f99f7f1d5317e1430f5bdfb719f7d6fee5b22d71..b8fc486e89e66e1fe218e9543e31eb43b4afe3d9 100644 (file)
@@ -22,7 +22,7 @@
 #include <libpspp/start-date.h>
 #include <libpspp/version.h>
 #include <output/afm.h>
-#include <output/chart.h>
+#include <output/chart-provider.h>
 #include <output/manager.h>
 #include <output/output.h>
 
@@ -57,9 +57,9 @@
    top-margin=0.5in
    bottom-margin=0.5in
 
-   prop-font=Times-Roman
-   emph-font=Times-Italic
-   fixed-font=Courier
+   prop-font=serif
+   emph-font=serif italic
+   fixed-font=monospace
    font-size=10000
 
    line-gutter=1pt
@@ -504,15 +504,24 @@ xr_close_page (struct outp_driver *this)
 }
 
 static void
-xr_submit (struct outp_driver *this UNUSED, struct som_entity *s)
+xr_output_chart (struct outp_driver *this, const struct chart *chart)
 {
-  switch (s->type)
-    {
-    case SOM_CHART:
-      break;
-    default:
-      NOT_REACHED ();
-    }
+  struct xr_driver_ext *x = this->ext;
+  struct chart_geometry geom;
+
+  outp_eject_page (this);
+  outp_open_page (this);
+
+  cairo_save (x->cairo);
+  cairo_translate (x->cairo, 0.0, xr_to_pt (this->length));
+  cairo_scale (x->cairo, 1.0, -1.0);
+  chart_geometry_init (x->cairo, &geom,
+                       xr_to_pt (this->width), xr_to_pt (this->length));
+  chart_draw (chart, x->cairo, &geom);
+  chart_geometry_free (x->cairo);
+  cairo_restore (x->cairo);
+
+  outp_close_page (this);
 }
 \f
 /* Draws a line from (x0,y0) to (x1,y1). */
@@ -840,24 +849,6 @@ xr_text_draw (struct outp_driver *this, const struct outp_text *t)
   text (this, t, true, NULL, NULL);
 }
 \f
-static void
-xr_chart_initialise (struct outp_driver *this UNUSED, struct chart *ch UNUSED)
-{
-#ifdef NO_CHARTS
-  ch->lp = NULL;
-#else
-  /* XXX libplot doesn't support Cairo yet. */
-#endif
-}
-
-static void
-xr_chart_finalise (struct outp_driver *this UNUSED, struct chart *ch UNUSED)
-{
-#ifndef NO_CHARTS
-  /* XXX libplot doesn't support Cairo yet. */
-#endif
-}
-\f
 /* Attempts to load FONT, initializing its other members based on
    its 'string' member and the information in THIS.  Returns true
    if successful, otherwise false. */
@@ -910,12 +901,11 @@ const struct outp_class cairo_class =
   xr_close_page,
   NULL,
 
-  xr_submit,
+  xr_output_chart,
+
+  NULL,
 
   xr_line,
   xr_text_metrics,
   xr_text_draw,
-
-  xr_chart_initialise,
-  xr_chart_finalise
 };