X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fcairo.c;h=045490992e1a9efce7eed26474e185ed4e212f01;hb=0ec7c606844768cfc501d6213ffa17ebdfda1bab;hp=fa9b2e18725e89c5f8c6edd9ccf9d7e6ffda8495;hpb=d3fef25674baf4f4e25502f257c680b5090535c6;p=pspp diff --git a/src/output/cairo.c b/src/output/cairo.c index fa9b2e1872..045490992e 100644 --- a/src/output/cairo.c +++ b/src/output/cairo.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc. + Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,15 +25,18 @@ #include "libpspp/str.h" #include "libpspp/string-map.h" #include "libpspp/version.h" +#include "data/file-handle-def.h" #include "output/cairo-chart.h" #include "output/chart-item-provider.h" #include "output/charts/boxplot.h" #include "output/charts/np-plot.h" #include "output/charts/piechart.h" +#include "output/charts/barchart.h" #include "output/charts/plot-hist.h" #include "output/charts/roc-chart.h" #include "output/charts/spreadlevel-plot.h" #include "output/charts/scree.h" +#include "output/charts/scatterplot.h" #include "output/driver-provider.h" #include "output/message-item.h" #include "output/options.h" @@ -286,7 +289,7 @@ apply_options (struct xr_driver *xr, struct string_map *o) xr->fonts[XR_FONT_MARKER].desc = parse_font (d, o, "marker-font", "serif", font_size * PANGO_SCALE_X_SMALL); - xr->line_gutter = 0; + xr->line_gutter = XR_POINT / 2; xr->line_space = XR_POINT; xr->line_width = XR_POINT / 2; xr->page_number = 0; @@ -473,24 +476,30 @@ xr_create (const char *file_name, enum settings_output_devices device_type, } static struct output_driver * -xr_pdf_create (const char *file_name, enum settings_output_devices device_type, +xr_pdf_create (struct file_handle *fh, enum settings_output_devices device_type, struct string_map *o) { - return xr_create (file_name, device_type, o, XR_PDF); + struct output_driver *od = xr_create (fh_get_file_name (fh), device_type, o, XR_PDF); + fh_unref (fh); + return od ; } static struct output_driver * -xr_ps_create (const char *file_name, enum settings_output_devices device_type, +xr_ps_create (struct file_handle *fh, enum settings_output_devices device_type, struct string_map *o) { - return xr_create (file_name, device_type, o, XR_PS); + struct output_driver *od = xr_create (fh_get_file_name (fh), device_type, o, XR_PS); + fh_unref (fh); + return od ; } static struct output_driver * -xr_svg_create (const char *file_name, enum settings_output_devices device_type, +xr_svg_create (struct file_handle *fh, enum settings_output_devices device_type, struct string_map *o) { - return xr_create (file_name, device_type, o, XR_SVG); + struct output_driver *od = xr_create (fh_get_file_name (fh), device_type, o, XR_SVG); + fh_unref (fh); + return od ; } static void @@ -562,24 +571,19 @@ xr_submit (struct output_driver *driver, const struct output_item *output_item) See the big comment in cairo.h for intended usage. */ -/* Gives new page CAIRO to XR for output. CAIRO may be null to skip actually - rendering the page (which might be useful to find out how many pages an - output document has without actually rendering it). */ +/* Gives new page CAIRO to XR for output. */ void xr_driver_next_page (struct xr_driver *xr, cairo_t *cairo) { - if (cairo != NULL) - { - cairo_save (cairo); - cairo_set_source_rgb (cairo, xr->bg.red, xr->bg.green, xr->bg.blue); - cairo_rectangle (cairo, 0, 0, xr->width, xr->length); - cairo_fill (cairo); - cairo_restore (cairo); - - cairo_translate (cairo, - xr_to_pt (xr->left_margin), - xr_to_pt (xr->top_margin)); - } + cairo_save (cairo); + cairo_set_source_rgb (cairo, xr->bg.red, xr->bg.green, xr->bg.blue); + cairo_rectangle (cairo, 0, 0, xr->width, xr->length); + cairo_fill (cairo); + cairo_restore (cairo); + + cairo_translate (cairo, + xr_to_pt (xr->left_margin), + xr_to_pt (xr->top_margin)); xr->page_number++; xr->cairo = cairo; @@ -707,9 +711,9 @@ xr_draw_line (void *xr_, int bb[TABLE_N_AXES][2], const int x3 = bb[H][1]; const int y3 = bb[V][1]; const int top = styles[H][0]; - const int left = styles[V][0]; const int bottom = styles[H][1]; - const int right = styles[V][1]; + const int start_of_line = render_direction_rtl() ? styles[V][1]: styles[V][0]; + const int end_of_line = render_direction_rtl() ? styles[V][0]: styles[V][1]; /* The algorithm here is somewhat subtle, to allow it to handle all the kinds of intersections that we need. @@ -749,7 +753,7 @@ xr_draw_line (void *xr_, int bb[TABLE_N_AXES][2], (It doesn't make sense to have different kinds of line on the same axis, so we don't try to gracefully handle that case.) */ bool double_vert = top == RENDER_LINE_DOUBLE || bottom == RENDER_LINE_DOUBLE; - bool double_horz = left == RENDER_LINE_DOUBLE || right == RENDER_LINE_DOUBLE; + bool double_horz = start_of_line == RENDER_LINE_DOUBLE || end_of_line == RENDER_LINE_DOUBLE; /* When horizontal lines are doubled, the left-side line along y1 normally runs from x0 to x2, @@ -784,8 +788,8 @@ xr_draw_line (void *xr_, int bb[TABLE_N_AXES][2], int x1 = xc - horz_line_ofs; int x2 = xc + horz_line_ofs; - bool shorten_x1_lines = left == RENDER_LINE_DOUBLE; - bool shorten_x2_lines = right == RENDER_LINE_DOUBLE; + bool shorten_x1_lines = start_of_line == RENDER_LINE_DOUBLE; + bool shorten_x2_lines = end_of_line == RENDER_LINE_DOUBLE; bool shorten_xc_line = shorten_x1_lines && shorten_x2_lines; int vert_line_ofs = double_horz ? double_line_ofs : 0; int yc = (y0 + y3) / 2; @@ -793,11 +797,11 @@ xr_draw_line (void *xr_, int bb[TABLE_N_AXES][2], int y2 = yc + vert_line_ofs; if (!double_horz) - horz_line (xr, x0, x1, x2, x3, yc, left, right, shorten_yc_line); + horz_line (xr, x0, x1, x2, x3, yc, start_of_line, end_of_line, shorten_yc_line); else { - horz_line (xr, x0, x1, x2, x3, y1, left, right, shorten_y1_lines); - horz_line (xr, x0, x1, x2, x3, y2, left, right, shorten_y2_lines); + horz_line (xr, x0, x1, x2, x3, y1, start_of_line, end_of_line, shorten_y1_lines); + horz_line (xr, x0, x1, x2, x3, y2, start_of_line, end_of_line, shorten_y2_lines); } if (!double_vert) @@ -845,8 +849,6 @@ xr_measure_cell_height (void *xr_, const struct table_cell *cell, bb[H][0] = 0; bb[H][1] = width - xr->cell_margin * 2; - if (bb[H][1] <= 0) - return 0; bb[V][0] = 0; bb[V][1] = INT_MAX; clip[H][0] = clip[H][1] = clip[V][0] = clip[V][1] = 0; @@ -1076,12 +1078,14 @@ xr_layout_cell_text (struct xr_driver *xr, { if (brk && clip[H][0] != clip[H][1]) best = bottom; - *brk = bottom; + if (brk) + *brk = bottom; } else break; } while (pango_layout_iter_next_line (iter)); + pango_layout_iter_free (iter); /* If enabled, draws a green line across the chosen breakpoint, which can be useful for debugging issues with breaking. */ @@ -1296,14 +1300,15 @@ 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 (TAB_LEFT, text), NULL); + table_item = table_item_create (table_from_string (TAB_LEFT, text), + NULL, NULL); r = xr_rendering_create (xr, &table_item->output_item, cr); table_item_unref (table_item); return r; } -void +void xr_rendering_apply_options (struct xr_rendering *xr, struct string_map *o) { if (is_table_item (xr->item)) @@ -1373,11 +1378,9 @@ xr_rendering_measure (struct xr_rendering *r, int *w, int *h) static void xr_draw_chart (const struct chart_item *, cairo_t *, double x, double y, double width, double height); -/* Draws onto CR at least the region of R that is enclosed in (X,Y)-(X+W,Y+H), - and possibly some additional parts. */ +/* Draws onto CR */ void -xr_rendering_draw (struct xr_rendering *r, cairo_t *cr, - int x, int y, int w, int h) +xr_rendering_draw_all (struct xr_rendering *r, cairo_t *cr) { if (is_table_item (r->item)) { @@ -1385,10 +1388,8 @@ xr_rendering_draw (struct xr_rendering *r, cairo_t *cr, xr_set_cairo (xr, cr); - xr->y = 0; - render_pager_draw_region (r->p, - x * XR_POINT, y * XR_POINT, - w * XR_POINT, h * XR_POINT); + render_pager_draw (r->p); + } else xr_draw_chart (to_chart_item (r->item), cr, @@ -1413,12 +1414,16 @@ xr_draw_chart (const struct chart_item *chart_item, cairo_t *cr, xrchart_draw_np_plot (chart_item, cr, &geom); else if (is_piechart (chart_item)) xrchart_draw_piechart (chart_item, cr, &geom); + else if (is_barchart (chart_item)) + xrchart_draw_barchart (chart_item, cr, &geom); else if (is_roc_chart (chart_item)) xrchart_draw_roc (chart_item, cr, &geom); else if (is_scree (chart_item)) xrchart_draw_scree (chart_item, cr, &geom); else if (is_spreadlevel_plot_chart (chart_item)) xrchart_draw_spreadlevel (chart_item, cr, &geom); + else if (is_scatterplot_chart (chart_item)) + xrchart_draw_scatterplot (chart_item, cr, &geom); else NOT_REACHED (); xrchart_geometry_free (cr, &geom); @@ -1600,7 +1605,8 @@ xr_create_text_renderer (struct xr_driver *xr, const char *text) struct table_item *table_item; struct xr_render_fsm *fsm; - table_item = table_item_create (table_from_string (TAB_LEFT, text), NULL); + table_item = table_item_create (table_from_string (TAB_LEFT, text), + NULL, NULL); fsm = xr_render_table (xr, table_item); table_item_unref (table_item);