Skip to content

Commit

Permalink
Honor vertical-align for fixed-height cells (related to #31)
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Apr 25, 2015
1 parent 54fde80 commit f4f8c25
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions weasyprint/layout/tables.py
Expand Up @@ -121,7 +121,7 @@ def group_layout(group, position_y, max_position_y,
+ border_spacing_x * (cell.colspan - 1)
- borders_plus_padding)
# The computed height is a minimum
computed_cell_height = cell.height
cell.computed_height = cell.height
cell.height = 'auto'
cell, _, _, _, _ = block_container_layout(
context, cell,
Expand All @@ -131,8 +131,9 @@ def group_layout(group, position_y, max_position_y,
page_is_empty=True,
absolute_boxes=absolute_boxes,
fixed_boxes=fixed_boxes)
if computed_cell_height != 'auto':
cell.height = max(cell.height, computed_cell_height)
cell.content_height = cell.height
if cell.computed_height != 'auto':
cell.height = max(cell.height, cell.computed_height)
new_row_children.append(cell)

row = row.copy_with_children(new_row_children)
Expand Down Expand Up @@ -177,6 +178,7 @@ def group_layout(group, position_y, max_position_y,
row.height = 0

# Add extra padding to make the cells the same height as the row
# and honor vertical-align
for cell in ending_cells:
cell_bottom_y = cell.position_y + cell.border_height()
extra = row_bottom_y - cell_bottom_y
Expand All @@ -188,6 +190,18 @@ def group_layout(group, position_y, max_position_y,
cell.padding_bottom += extra
else:
cell.padding_bottom += extra
if cell.computed_height != 'auto':
vertical_align_shift = 0
if cell.vertical_align == 'middle':
vertical_align_shift = (
cell.computed_height - cell.content_height) / 2
elif cell.vertical_align == 'bottom':
vertical_align_shift = (
cell.computed_height - cell.content_height)
# TODO: elif cell.vertical_align == 'baseline':
if vertical_align_shift > 0:
for child in cell.children:
child.translate(dy=vertical_align_shift)

next_position_y = position_y + row.height + border_spacing_y
# Break if this row overflows the page, unless there is no
Expand Down

0 comments on commit f4f8c25

Please sign in to comment.