From 5d626fa11b736925983b615d4e3fba000a0ce75b Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 24 Nov 2018 12:33:16 -0800 Subject: [PATCH] output: Add support for alternating row colors. --- src/output/ascii.c | 4 ++-- src/output/cairo.c | 16 ++++++++-------- src/output/render.c | 7 ++++++- src/output/render.h | 2 +- src/output/table-provider.h | 6 +++--- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/output/ascii.c b/src/output/ascii.c index c2c5dd54fd..d4032483da 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -220,7 +220,7 @@ static void ascii_measure_cell_width (void *, const struct table_cell *, int *min, int *max); static int ascii_measure_cell_height (void *, const struct table_cell *, int width); -static void ascii_draw_cell (void *, const struct table_cell *, +static void ascii_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]); @@ -612,7 +612,7 @@ ascii_measure_cell_height (void *a_, const struct table_cell *cell, int width) } static void -ascii_draw_cell (void *a_, const struct table_cell *cell, +ascii_draw_cell (void *a_, const struct table_cell *cell, int color_idx UNUSED, int bb[TABLE_N_AXES][2], int spill[TABLE_N_AXES][2] UNUSED, int clip[TABLE_N_AXES][2]) diff --git a/src/output/cairo.c b/src/output/cairo.c index 0176d3caa2..43788cecf5 100644 --- a/src/output/cairo.c +++ b/src/output/cairo.c @@ -172,7 +172,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]); @@ -919,7 +919,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 +941,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 +953,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++) { diff --git a/src/output/render.c b/src/output/render.c index eb5f1cfe1a..23ef992727 100644 --- a/src/output/render.c +++ b/src/output/render.c @@ -1028,7 +1028,12 @@ render_cell (const struct render_page *page, const int ofs[TABLE_N_AXES], spill[axis][1] = rule_width (page, axis, cell->d[axis][1]) / 2; } - page->params->draw_cell (page->params->aux, cell, bb, spill, clip); + int color_idx = (cell->d[V][0] < page->h[V][0] + || page->n[V] - (cell->d[V][0] + 1) < page->h[V][1] + ? 0 + : (cell->d[V][0] - page->h[V][0]) & 1); + page->params->draw_cell (page->params->aux, cell, color_idx, + bb, spill, clip); } /* Draws the cells of PAGE indicated in BB. */ diff --git a/src/output/render.h b/src/output/render.h index cceea9e723..600bfd9344 100644 --- a/src/output/render.h +++ b/src/output/render.h @@ -100,7 +100,7 @@ struct render_params case) or a subregion enclosed by BB. In the latter case only the part of the cell that lies within CLIP should actually be drawn, although BB should used to determine the layout of the cell. */ - void (*draw_cell) (void *aux, const struct table_cell *cell, + void (*draw_cell) (void *aux, 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]); diff --git a/src/output/table-provider.h b/src/output/table-provider.h index 2917051a13..1d21cdfd5c 100644 --- a/src/output/table-provider.h +++ b/src/output/table-provider.h @@ -62,7 +62,7 @@ cell_color_equal (const struct cell_color *a, const struct cell_color *b) struct cell_style { - struct cell_color fg, bg; + struct cell_color fg[2], bg[2]; int margin[TABLE_N_AXES][2]; char *font; int font_size; @@ -71,8 +71,8 @@ struct cell_style #define CELL_STYLE_INITIALIZER \ { \ - .fg = CELL_COLOR_BLACK, \ - .bg = CELL_COLOR_WHITE, \ + .fg = { [0] = CELL_COLOR_BLACK, [1] = CELL_COLOR_BLACK}, \ + .bg = { [0] = CELL_COLOR_WHITE, [1] = CELL_COLOR_WHITE}, \ .margin = { [TABLE_HORZ][0] = 8, [TABLE_HORZ][1] = 11, \ [TABLE_VERT][0] = 1, [TABLE_VERT][1] = 1 }, \ .font = NULL, \ -- 2.30.2