output: Add support for alternating row colors.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 24 Nov 2018 20:33:16 +0000 (12:33 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 25 Dec 2018 20:52:07 +0000 (12:52 -0800)
src/output/ascii.c
src/output/cairo.c
src/output/render.c
src/output/render.h
src/output/table-provider.h

index c2c5dd54fd55863dd6580e7bfabb07ff8442c3b8..d4032483da7132c609370d4952d7901745525f9f 100644 (file)
@@ -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])
index 0176d3caa22b3ace45c83fd349e14e15cf4aaee6..43788cecf5fde9ddd8e141cadc21e37008f4db0d 100644 (file)
@@ -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++)
     {
index eb5f1cfe1aa213d1da56221fcc17e652e9fcf45c..23ef9927275be3f119077075d46e98efcc078dff 100644 (file)
@@ -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. */
index cceea9e72323a95edbef1083ecf2da07740cc844..600bfd93449982e3608b717e029a787964a6ad10 100644 (file)
@@ -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]);
index 2917051a13039c3f0d015bf4891bb6971b7eb5cf..1d21cdfd5c374a140270c4742a899f6187482cfc 100644 (file)
@@ -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,                                             \