Skip to content

Commit

Permalink
table: Apply the gutter spacing between outer border and table conten…
Browse files Browse the repository at this point in the history
…ts [py-pdf#1071]
  • Loading branch information
mjasperse committed Dec 23, 2023
1 parent b7c2215 commit c964d88
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions fpdf/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,17 @@ def render(self):
self._fpdf.l_margin = self._fpdf.x

# Pre-Compute the relative x-positions of the individual columns:
cell_x_positions = [0]
xx = self._gutter_width if self._outer_border_width else 0
cell_x_positions = [xx]
if self.rows:
xx = 0
for i in range(self.rows[0].cols_count):
xx += self._get_col_width(0, i)
xx += self._gutter_width
cell_x_positions.append(xx)

# Starting the actual rows & cells rendering:
if self._outer_border_width:
self._fpdf.y += self._gutter_height
for i in range(len(self.rows)):
row_layout_info = self._get_row_layout_info(i)
if row_layout_info.triggers_page_jump:
Expand Down Expand Up @@ -384,16 +386,22 @@ def _render_table_cell(
_remember_linewidth = self._fpdf.line_width
self._fpdf.set_line_width(self._outer_border_width)

gutter_x = self._gutter_width if j != 0 else 0
gutter_y = self._gutter_height if i != 0 else 0
# draw the outer box separated by the gutter dimensions
if j == 0:
x1 = x1 - self._gutter_width
if i == 0:
y1 = y1 - self._gutter_height
x2 = x2 + self._gutter_width
y2 = y2 + self._gutter_height

if i == 0:
self._fpdf.line(x1 - gutter_x, y1, x2, y1)
self._fpdf.line(x1, y1, x2, y1)
if i == len(self.rows) - 1:
self._fpdf.line(x1 - gutter_x, y2, x2, y2)
self._fpdf.line(x1, y2, x2, y2)
if j == 0:
self._fpdf.line(x1, y1 - gutter_y, x1, y2)
self._fpdf.line(x1, y1, x1, y2)
if j == len(row.cells) - 1:
self._fpdf.line(x2, y1 - gutter_y, x2, y2)
self._fpdf.line(x2, y1, x2, y2)

self._fpdf.set_line_width(_remember_linewidth)

Expand Down Expand Up @@ -484,6 +492,8 @@ def _get_col_width(self, i, j, colspan=1):

cols_count = self.rows[i].cols_count
width = self._width - (cols_count - 1) * self._gutter_width
if self._outer_border_width:
width -= 2 * self._gutter_width

gutter_within_cell = max((colspan - 1) * self._gutter_width, 0)

Expand Down

0 comments on commit c964d88

Please sign in to comment.