- if (needed_size (b, cell + 1) > size)
- {
- if (!cell_is_breakable (b, cell))
- {
- if (cell == b->cell)
- return NULL;
- }
- else
- pixel = (cell == b->cell
- ? b->pixel + size - b->hw
- : size - needed_size (b, cell));
- break;
- }
+ {
+ int needed = needed_size (b, cell + 1);
+ if (needed > size)
+ {
+ if (cell_is_breakable (b, cell))
+ {
+ /* If there is no right header and we render a partial cell on
+ the right side of the body, then we omit the rightmost rule of
+ the body. Otherwise the rendering is deceptive because it
+ looks like the whole cell is present instead of a partial
+ cell.
+
+ This is similar to code for the left side in needed_size(). */
+ int rule_allowance = (page->h[axis][1]
+ ? 0
+ : rule_width (page, axis, cell));
+
+ /* The amount that, if we added 'cell', the rendering would
+ overfill the allocated 'size'. */
+ int overhang = needed - size - rule_allowance;
+
+ /* The width of 'cell'. */
+ int cell_size = cell_width (page, axis, cell);
+
+ /* The amount trimmed the left side of 'cell',
+ and the amount left to render. */
+ int cell_ofs = cell == b->cell ? b->pixel : 0;
+ int cell_left = cell_size - cell_ofs;
+
+ /* A small but visible width. */
+ int em = page->params->font_size[axis];
+
+ /* If some of the cell remains to render,
+ and there would still be some of the cell left afterward,
+ then partially render that much of the cell. */
+ pixel = (cell_left && cell_left > overhang
+ ? cell_left - overhang + cell_ofs
+ : 0);
+
+ /* If there would be only a tiny amount of the cell left after
+ rendering it partially, reduce the amount rendered slightly
+ to make the output look a little better. */
+ if (pixel + em > cell_size)
+ pixel = MAX (pixel - em, 0);
+ }
+ break;
+ }
+ }
+
+ if (cell == b->cell && !pixel)
+ return NULL;