@@ -15,15 +15,18 @@ def table_layout(context, table, bottom_space, skip_stack, containing_block,
15
15
avoid_page_break , block_container_layout , block_level_page_break ,
16
16
find_earlier_page_break , force_page_break )
17
17
18
- table .remove_decoration (start = skip_stack is not None , end = False )
18
+ has_header = table .children and table .children [0 ].is_header
19
+ has_footer = table .children and table .children [- 1 ].is_footer
20
+ collapse = table .style ['border_collapse' ] == 'collapse'
21
+ remove_start_decoration = skip_stack is not None and not has_header
22
+ table .remove_decoration (remove_start_decoration , end = False )
19
23
20
24
column_widths = table .column_widths
21
25
22
- if table . style [ 'border_collapse' ] == 'separate' :
23
- border_spacing_x , border_spacing_y = table . style [ 'border_spacing' ]
26
+ if collapse :
27
+ border_spacing_x = border_spacing_y = 0
24
28
else :
25
- border_spacing_x = 0
26
- border_spacing_y = 0
29
+ border_spacing_x , border_spacing_y = table .style ['border_spacing' ]
27
30
28
31
column_positions = table .column_positions = []
29
32
rows_left_x = table .content_box_x () + border_spacing_x
@@ -44,7 +47,7 @@ def table_layout(context, table, bottom_space, skip_stack, containing_block,
44
47
column_positions .append (position_x )
45
48
rows_width = rows_x - position_x
46
49
47
- if table . style [ 'border_collapse' ] == ' collapse' :
50
+ if collapse :
48
51
table .skip_cell_border_top = False
49
52
table .skip_cell_border_bottom = False
50
53
split_cells = False
@@ -60,7 +63,7 @@ def table_layout(context, table, bottom_space, skip_stack, containing_block,
60
63
skipped_rows += len (group .children )
61
64
else :
62
65
skipped_rows = 0
63
- if not split_cells :
66
+ if not split_cells and not has_header :
64
67
_ , horizontal_borders = table .collapsed_border_grid
65
68
if horizontal_borders :
66
69
table .border_top_width = max (
@@ -149,9 +152,20 @@ def group_layout(group, position_y, bottom_space, page_is_empty,
149
152
cell_skip_stack = {len (cell .children ): None }
150
153
else :
151
154
cell_skip_stack = None
152
- if cell_skip_stack :
153
- cell .remove_decoration (start = True , end = False )
154
- if table .style ['border_collapse' ] == 'collapse' :
155
+
156
+ # Adapt cell and table collapsing borders when a row is split
157
+ if cell_skip_stack and collapse :
158
+ if has_header :
159
+ # We have a header, we have to adapt the position of
160
+ # the split cell to match the header’s bottom border
161
+ header_rows = table .children [0 ].children
162
+ if header_rows and header_rows [- 1 ].children :
163
+ cell .position_y += max (
164
+ header .border_bottom_width
165
+ for header in header_rows [- 1 ].children )
166
+ else :
167
+ # We don’t have a header, we have to skip the
168
+ # decoration at the top of the table when it’s drawn
155
169
table .skip_cell_border_top = True
156
170
157
171
# First try to render content as if there was already something
@@ -308,7 +322,7 @@ def group_layout(group, position_y, bottom_space, page_is_empty,
308
322
page_is_empty = False
309
323
skip_stack = None
310
324
311
- if break_cell and table . style [ 'border_collapse' ] == 'collapse' :
325
+ if break_cell and collapse and not has_footer :
312
326
table .skip_cell_border_bottom = True
313
327
314
328
if break_cell or resume_at :
@@ -422,7 +436,7 @@ def all_groups_layout():
422
436
else :
423
437
header_footer_bottom_space = - inf
424
438
425
- if table . children and table . children [ 0 ]. is_header :
439
+ if has_header :
426
440
header = table .children [0 ]
427
441
header , resume_at , next_page = group_layout (
428
442
header , position_y , header_footer_bottom_space ,
@@ -434,7 +448,7 @@ def all_groups_layout():
434
448
else :
435
449
header = None
436
450
437
- if table . children and table . children [ - 1 ]. is_footer :
451
+ if has_footer :
438
452
footer = table .children [- 1 ]
439
453
footer , resume_at , next_page = group_layout (
440
454
footer , position_y , header_footer_bottom_space ,
@@ -536,9 +550,9 @@ def get_column_cells(table, column):
536
550
([header ] if header is not None else []) +
537
551
new_table_children +
538
552
([footer ] if footer is not None else []))
539
- table . remove_decoration (
540
- start = skip_stack is not None , end = resume_at is not None )
541
- if table . style [ 'border_collapse' ] == ' collapse' :
553
+ remove_end_decoration = resume_at is not None and not has_footer
554
+ table . remove_decoration ( remove_start_decoration , remove_end_decoration )
555
+ if collapse :
542
556
table .skipped_rows = skipped_rows
543
557
544
558
# If the height property has a bigger value, just add blank space
0 commit comments