X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fcairo.c;h=49a7f7ed3dda709f52280480151e5ca04fa71b55;hb=259b5c32c06fd93964720f4a0e7844b5a24c55db;hp=a3070dddef3e2e69dc65ff58a3c4c8f1b82d7739;hpb=3ccf4f19ece6c4da5a2d13173c032011faf330b8;p=pspp diff --git a/src/output/cairo.c b/src/output/cairo.c index a3070dddef..49a7f7ed3d 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, 2015 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,6 +25,7 @@ #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" @@ -475,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 @@ -704,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. @@ -746,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, @@ -781,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; @@ -790,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) @@ -842,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; @@ -1073,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. */ @@ -1098,81 +1105,6 @@ xr_layout_cell_text (struct xr_driver *xr, return y + h; } -static int -xr_layout_cell_subtable (struct xr_driver *xr, - const struct cell_contents *contents, - int footnote_idx UNUSED, - int bb[TABLE_N_AXES][2], - int clip[TABLE_N_AXES][2], int *widthp, int *brk) -{ - int single_width, double_width; - struct render_params params; - struct render_pager *p; - int r[TABLE_N_AXES][2]; - int width, height; - int i; - - params.draw_line = xr_draw_line; - params.measure_cell_width = xr_measure_cell_width; - params.measure_cell_height = xr_measure_cell_height; - params.adjust_break = NULL; - params.draw_cell = xr_draw_cell; - params.aux = xr; - params.size[H] = bb[H][1] - bb[H][0]; - params.size[V] = bb[V][1] - bb[V][0]; - params.font_size[H] = xr->char_width; - params.font_size[V] = xr->char_height; - - single_width = 2 * xr->line_gutter + xr->line_width; - double_width = 2 * xr->line_gutter + xr->line_space + 2 * xr->line_width; - for (i = 0; i < TABLE_N_AXES; i++) - { - params.line_widths[i][RENDER_LINE_NONE] = 0; - params.line_widths[i][RENDER_LINE_SINGLE] = single_width; - params.line_widths[i][RENDER_LINE_DOUBLE] = double_width; - } - - xr->nest++; - p = render_pager_create (¶ms, contents->table); - width = render_pager_get_size (p, H); - height = render_pager_get_size (p, V); - if (bb[V][0] + height >= bb[V][1]) - *brk = bb[V][0] + render_pager_get_best_breakpoint (p, bb[V][1] - bb[V][0]); - - /* r = intersect(bb, clip) - bb. */ - for (i = 0; i < TABLE_N_AXES; i++) - { - r[i][0] = MAX (bb[i][0], clip[i][0]) - bb[i][0]; - r[i][1] = MIN (bb[i][1], clip[i][1]) - bb[i][0]; - } - - if (r[H][0] < r[H][1] && r[V][0] < r[V][1]) - { - unsigned int alignment = contents->options & TAB_ALIGNMENT; - int save_x = xr->x; - - cairo_save (xr->cairo); - xr_clip (xr, clip); - xr->x += bb[H][0]; - if (alignment == TAB_RIGHT) - xr->x += params.size[H] - width; - else if (alignment == TAB_CENTER) - xr->x += (params.size[H] - width) / 2; - xr->y += bb[V][0]; - render_pager_draw_region (p, r[H][0], r[V][0], - r[H][1] - r[H][0], r[V][1] - r[V][0]); - xr->y -= bb[V][0]; - xr->x = save_x; - cairo_restore (xr->cairo); - } - render_pager_destroy (p); - xr->nest--; - - if (width > *widthp) - *widthp = width; - return bb[V][0] + height; -} - static void xr_layout_cell (struct xr_driver *xr, const struct table_cell *cell, int footnote_idx, @@ -1221,12 +1153,8 @@ xr_layout_cell (struct xr_driver *xr, const struct table_cell *cell, *brk = bb[V][0]; } - if (contents->text) - bb[V][0] = xr_layout_cell_text (xr, contents, footnote_idx, bb, clip, - bb[V][0], width, brk); - else - bb[V][0] = xr_layout_cell_subtable (xr, contents, footnote_idx, - bb, clip, width, brk); + bb[V][0] = xr_layout_cell_text (xr, contents, footnote_idx, bb, clip, + bb[V][0], width, brk); footnote_idx += contents->n_footnotes; } *height = bb[V][0] - bb_[V][0]; @@ -1301,7 +1229,7 @@ xr_rendering_create_text (struct xr_driver *xr, const char *text, cairo_t *cr) return r; } -void +void xr_rendering_apply_options (struct xr_rendering *xr, struct string_map *o) { if (is_table_item (xr->item)) @@ -1535,13 +1463,20 @@ xr_chart_render (struct xr_render_fsm *fsm, struct xr_driver *xr) { struct xr_chart_state *cs = UP_CAST (fsm, struct xr_chart_state, fsm); - if (xr->y > 0) + const int chart_height = 0.8 * (xr->length < xr->width ? xr->length : xr->width); + + if (xr->y > xr->length - chart_height) return true; if (xr->cairo != NULL) - xr_draw_chart (cs->chart_item, xr->cairo, 0.0, 0.0, - xr_to_pt (xr->width), xr_to_pt (xr->length)); - xr->y = xr->length; + { + xr_draw_chart (cs->chart_item, xr->cairo, + 0.0, + xr_to_pt (xr->y), + xr_to_pt (xr->width), + xr_to_pt (chart_height)); + } + xr->y += chart_height; return false; }