Skip to content

Commit

Permalink
Fix table paddings and minor regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Jan 29, 2016
1 parent c42bf6a commit c323759
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
53 changes: 38 additions & 15 deletions weasyprint/layout/preferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def min_content_width(context, box, outer=True):
boxes.BlockContainerBox, boxes.TableColumnBox,
boxes.TableColumnGroupBox)):
if box.is_table_wrapper:
return table_and_columns_preferred_widths(context, box, outer)[1]
return table_and_columns_preferred_widths(context, box, outer)[0]
else:
return block_min_content_width(context, box, outer)
elif isinstance(box, (boxes.InlineBox, boxes.LineBox)):
Expand Down Expand Up @@ -277,7 +277,7 @@ def table_and_columns_preferred_widths(context, box, outer=True):
table = box.get_wrapped_table()
result = TABLE_CACHE.get(table)
if result:
return result
return result[outer]

# Create the grid
grid_width, grid_height = 0, 0
Expand Down Expand Up @@ -308,12 +308,20 @@ def table_and_columns_preferred_widths(context, box, outer=True):

if grid_width == 0 or grid_height == 0:
table.children = []
min_width = block_min_content_width(context, table)
max_width = block_max_content_width(context, table)
TABLE_CACHE[table] = result = (
min_width, max_width, [], [], [], [],
total_horizontal_border_spacing, [])
return result
min_width = block_min_content_width(context, table, outer=False)
max_width = block_max_content_width(context, table, outer=False)
outer_min_width = adjust(
box, outer=True, width=block_min_content_width(
context, table, outer=True))
outer_max_width = adjust(
box, outer=True, width=block_max_content_width(
context, table, outer=True))
result = ([], [], [], [], total_horizontal_border_spacing, [])
TABLE_CACHE[table] = result = {
False: (min_width, max_width) + result,
True: (outer_min_width, outer_max_width) + result,
}
return result[outer]

column_groups = [None] * grid_width
columns = [None] * grid_width
Expand Down Expand Up @@ -507,17 +515,32 @@ def table_and_columns_preferred_widths(context, box, outer=True):
else:
table_min_width = table_min_content_width
table_max_width = table_max_content_width
table_min_content_width = max(
adjust(table, outer, table_min_width), table_min_content_width)
table_max_content_width = max(
adjust(table, outer, table_max_width), table_max_content_width)

table_min_content_width = adjust(
table, outer=False,
width=max(table_min_width, table_min_content_width))
table_max_content_width = adjust(
table, outer=False,
width=max(table_max_width, table_max_content_width))
table_outer_min_content_width = adjust(
box, outer=True, width=adjust(
table, outer=True,
width=max(table_min_width, table_min_content_width)))
table_outer_max_content_width = adjust(
box, outer=True, width=adjust(
table, outer=True,
width=max(table_max_width, table_max_content_width)))

result = (
table_min_content_width, table_max_content_width,
min_content_widths, max_content_widths, intrinsic_percentages,
constrainedness, total_horizontal_border_spacing, zipped_grid)
TABLE_CACHE[table] = result
return result
TABLE_CACHE[table] = result = {
False: (table_min_content_width, table_max_content_width) + result,
True: (
(table_outer_min_content_width, table_outer_max_content_width) +
result),
}
return result[outer]


def replaced_min_content_width(box, outer=True):
Expand Down
9 changes: 4 additions & 5 deletions weasyprint/layout/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def group_layout(group, position_y, max_position_y,
for child in cell.children:
child.translate(dy=vertical_align_shift)

next_position_y = position_y + row.height + border_spacing_y
next_position_y = row.position_y + row.height + border_spacing_y
# Break if this row overflows the page, unless there is no
# other content on the page.
if next_position_y > max_position_y and not page_is_empty:
Expand Down Expand Up @@ -530,9 +530,10 @@ def auto_table_layout(context, box, containing_block):
margins += box.margin_left
if box.margin_right != 'auto':
margins += box.margin_right
paddings = table.padding_left + table.padding_right

cb_width, _ = containing_block
available_width = cb_width - margins
available_width = cb_width - margins - paddings

if table.width == 'auto':
if available_width <= table_min_content_width:
Expand Down Expand Up @@ -593,9 +594,7 @@ def auto_table_layout(context, box, containing_block):
# Distribute available width to columns
# http://dbaron.org/css/intrinsic/#distributetocols
table.column_widths = max_content_guess
excess_width = (
assignable_width - sum(max_content_guess) -
table.padding_left - table.padding_right)
excess_width = assignable_width - sum(max_content_guess)

# First group
columns = [
Expand Down

0 comments on commit c323759

Please sign in to comment.