render: Fix rendering of backgrounds in middle- or bottom-justified cells.
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 29 Oct 2020 05:55:10 +0000 (22:55 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 29 Oct 2020 05:55:10 +0000 (22:55 -0700)
src/output/ascii.c
src/output/cairo.c
src/output/render.c
src/output/render.h

index 3113997e4893d515d73d59778e54b0b18562cde2..a5faa1f81409a819b5e50496dcb38b8cc71087a7 100644 (file)
@@ -235,7 +235,7 @@ static void ascii_measure_cell_width (void *, const struct table_cell *,
 static int ascii_measure_cell_height (void *, const struct table_cell *,
                                       int width);
 static void ascii_draw_cell (void *, const struct table_cell *, int color_idx,
-                             int bb[TABLE_N_AXES][2],
+                             int bb[TABLE_N_AXES][2], int valign_offset,
                              int spill[TABLE_N_AXES][2],
                              int clip[TABLE_N_AXES][2]);
 
@@ -632,13 +632,14 @@ 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, int color_idx UNUSED,
-                 int bb[TABLE_N_AXES][2],
+                 int bb[TABLE_N_AXES][2], int valign_offset,
                  int spill[TABLE_N_AXES][2] UNUSED,
                  int clip[TABLE_N_AXES][2])
 {
   struct ascii_driver *a = a_;
   int w, h;
 
+  bb[V][0] += valign_offset;
   ascii_layout_cell (a, cell, bb, clip, &w, &h);
 }
 
index b733c941fd103711d26bb690262ed408cf0be839..2bfa3228a17a7c1eaaf61cb7ef8b696a91427b5d 100644 (file)
@@ -193,7 +193,7 @@ static void xr_measure_cell_width (void *, const struct table_cell *,
 static int xr_measure_cell_height (void *, const struct table_cell *,
                                    int width);
 static void xr_draw_cell (void *, const struct table_cell *, int color_idx,
-                          int bb[TABLE_N_AXES][2],
+                          int bb[TABLE_N_AXES][2], int valign_offset,
                           int spill[TABLE_N_AXES][2],
                           int clip[TABLE_N_AXES][2]);
 static int xr_adjust_break (void *, const struct table_cell *,
@@ -1358,7 +1358,7 @@ 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, int color_idx,
-              int bb[TABLE_N_AXES][2],
+              int bb[TABLE_N_AXES][2], int valign_offset,
               int spill[TABLE_N_AXES][2],
               int clip[TABLE_N_AXES][2])
 {
@@ -1392,6 +1392,8 @@ xr_draw_cell (void *xr_, const struct table_cell *cell, int color_idx,
   if (!xr->systemcolors)
     set_source_rgba (xr->cairo, &cell->style->font_style.fg[color_idx]);
 
+  bb[V][0] += valign_offset;
+
   for (int axis = 0; axis < TABLE_N_AXES; axis++)
     {
       bb[axis][0] += px_to_xr (cell->style->cell_style.margin[axis][0]);
index 06360eeecb32eaeacd652407cc6877a277a01697..890741a3f904725f1a7adb99482a5d5f31a1ae85 100644 (file)
@@ -1079,6 +1079,7 @@ render_cell (const struct render_page *page, const int ofs[TABLE_N_AXES],
   bb[V][1] = clip[V][1] = ofs[V] + page->cp[V][cell->d[V][1] * 2];
 
   enum table_valign valign = cell->style->cell_style.valign;
+  int valign_offset = 0;
   if (valign != TABLE_VALIGN_TOP)
     {
       int height = page->params->measure_cell_height (
@@ -1088,7 +1089,7 @@ render_cell (const struct render_page *page, const int ofs[TABLE_N_AXES],
         {
           if (valign == TABLE_VALIGN_CENTER)
             extra /= 2;
-          bb[V][0] += extra;
+          valign_offset += extra;
         }
     }
 
@@ -1125,7 +1126,7 @@ render_cell (const struct render_page *page, const int ofs[TABLE_N_AXES],
                    ? 0
                    : (cell->d[V][0] - page->h[V][0]) & 1);
   page->params->draw_cell (page->params->aux, cell, color_idx,
-                           bb, spill, clip);
+                           bb, valign_offset, spill, clip);
 }
 
 /* Draws the cells of PAGE indicated in BB. */
index c10f23716060924897da482dc106128fbd5cdcf3..7375d1a2a81b66d78dcda280c110ccfc161ebe21 100644 (file)
@@ -99,9 +99,16 @@ struct render_params
     /* Draws CELL within bounding box BB.  CLIP is the same as BB (the common
        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. */
+       should used to determine the layout of the cell.
+
+       The text in the cell needs to be vertically offset VALIGN_OFFSET units
+       from the top of the bounding box.  This handles vertical alignment with
+       the cell.  (The caller doesn't just reduce the bounding box size because
+       that would prevent the implementation from filling the entire cell with
+       the background color.)  The implementation must handle horizontal
+       alignment itself. */
     void (*draw_cell) (void *aux, const struct table_cell *cell, int color_idx,
-                       int bb[TABLE_N_AXES][2],
+                       int bb[TABLE_N_AXES][2], int valign_offset,
                        int spill[TABLE_N_AXES][2],
                        int clip[TABLE_N_AXES][2]);