1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-04 16:07:57 +03:00

Collapsed borders intersections should be rectangles, not squares.

This commit is contained in:
Simon Sapin 2012-07-11 19:33:11 +02:00
parent e955781b91
commit 0d3d1f1fd5
3 changed files with 42 additions and 11 deletions

View File

@ -579,16 +579,28 @@ def draw_collapsed_borders(document, context, table):
segments = []
def half_max_width(border_list, yx_pairs, vertical=True):
result = 0
for y, x in yx_pairs:
if (
(0 <= y < grid_height and 0 <= x <= grid_width)
if vertical else
(0 <= y <= grid_height and 0 <= x < grid_width)
):
_, (_, width, _) = border_list[skipped_rows + y][x]
result = max(result, width)
return result / 2
def add_vertical(x, y):
score, (style, width, color) = vertical_borders[skipped_rows + y][x]
if width == 0 or color.alpha == 0:
return
half_width = width / 2
pos_x = column_positions[x]
# Add half the width on both ends. With 'solid', this is like
# a square line cap.
pos_y_1 = row_positions[y] - half_width
pos_y_2 = row_positions[y + 1] + half_width
pos_y_1 = row_positions[y] - half_max_width(horizontal_borders, [
(y, x - 1), (y, x)], vertical=False)
pos_y_2 = row_positions[y + 1] + half_max_width(horizontal_borders, [
(y + 1, x - 1), (y + 1, x)], vertical=False)
edge_1 = (pos_x - half_width, pos_y_1), (pos_x - half_width, pos_y_2)
edge_2 = (pos_x + half_width, pos_y_1), (pos_x + half_width, pos_y_2)
segments.append((score, style, width, color, 'left', edge_1, edge_2))
@ -599,8 +611,11 @@ def draw_collapsed_borders(document, context, table):
return
half_width = width / 2
pos_y = row_positions[y]
pos_x_1 = column_positions[x] - half_width
pos_x_2 = column_positions[x + 1] + half_width
# TODO: change signs for rtl when we support rtl tables?
pos_x_1 = column_positions[x] - half_max_width(vertical_borders, [
(y - 1, x), (y, x)])
pos_x_2 = column_positions[x + 1] + half_max_width(vertical_borders, [
(y - 1, x + 1), (y, x + 1)])
edge_1 = (pos_x_1, pos_y - half_width), (pos_x_2, pos_y - half_width)
edge_2 = (pos_x_1, pos_y + half_width), (pos_x_2, pos_y + half_width)
segments.append((score, style, width, color, 'top', edge_1, edge_2))
@ -616,7 +631,7 @@ def draw_collapsed_borders(document, context, table):
# Sort bigger scores last (painted later, on top)
# Since the number of different scores is expected to be small compared
# to the number of segments, there should be little changes and Timsort
# should take less than O(n * log(n))
# should be closer to O(n) than O(n * log(n))
segments.sort(key=operator.itemgetter(0))
for segment in segments:

View File

@ -60,6 +60,10 @@ def table_layout(document, table, max_position_y, skip_stack,
skipped_rows += len(group.children)
else:
skipped_rows = 0
_, horizontal_borders = table.collapsed_border_grid
table.style.border_top_width = table.border_top_width = max(
width for _, (_, width, _) in horizontal_borders[skipped_rows]
) / 2
# Make this a sub-function so that many local variables like rows_x
# need not be passed as parameters.

View File

@ -1258,12 +1258,18 @@ def test_tables():
td { border-color: #ff7f7f }
'''})
assert_pixels('table_collapsed_borders_paged', 28, 40, [
assert_pixels('table_collapsed_borders_paged', 28, 52, [
_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_,
_+g+g+g+g+g+g+g+g+g+g+g+g+g+g+g+g+g+g+g+g+g+g+g+g+g+g+_,
_+g+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+g+_,
_+g+_+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+_+_+_+_+_+g+_,
_+g+_+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+_+_+_+_+_+g+_,
_+g+_+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+_+_+_+_+_+g+_,
_+g+_+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+_+_+_+_+_+g+_,
_+g+_+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+_+_+_+_+_+g+_,
_+g+_+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+_+_+_+_+_+g+_,
_+g+_+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+B+_+_+_+_+_+g+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_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_,
], source % {'extra_css': '''
table { border: 2px solid #00f; table-layout: fixed;
border-collapse: collapse }
table { border: solid #00f; border-width: 8px 2px;
table-layout: fixed; border-collapse: collapse }
td { border-color: #ff7f7f }
@page { size: 28px 20px; margin: 1px;
@page { size: 28px 26px; margin: 1px;
border: 1px solid rgba(0, 255, 0, 0.5); }
'''}, nb_pages=2)