From: Ben Pfaff Date: Thu, 29 Oct 2020 05:55:10 +0000 (-0700) Subject: render: Fix rendering of backgrounds in middle- or bottom-justified cells. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ee628352468d784b0de31f0f8e73717e25c322a;p=pspp render: Fix rendering of backgrounds in middle- or bottom-justified cells. --- diff --git a/src/output/ascii.c b/src/output/ascii.c index 3113997e48..a5faa1f814 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -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); } diff --git a/src/output/cairo.c b/src/output/cairo.c index b733c941fd..2bfa3228a1 100644 --- a/src/output/cairo.c +++ b/src/output/cairo.c @@ -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]); diff --git a/src/output/render.c b/src/output/render.c index 06360eeecb..890741a3f9 100644 --- a/src/output/render.c +++ b/src/output/render.c @@ -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. */ diff --git a/src/output/render.h b/src/output/render.h index c10f237160..7375d1a2a8 100644 --- a/src/output/render.h +++ b/src/output/render.h @@ -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]);