1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-05 08:27:22 +03:00

Handle justify-content

This commit is contained in:
Guillaume Ayoub 2018-01-11 01:01:14 +01:00
parent ce342cf0a2
commit d040b798a0
3 changed files with 29 additions and 7 deletions

View File

@ -182,6 +182,7 @@ INITIAL_VALUES = {
'flex_grow': 0,
'flex_shrink': 1,
'flex_wrap': 'nowrap',
'justify_content': 'flex-start',
'order': 0,
# Proprietary

View File

@ -1392,6 +1392,14 @@ def flex_wrap(keyword):
return keyword in ('nowrap', 'wrap', 'wrap-reverse')
@validator()
@single_keyword
def justify_content(keyword):
"""``justify_content`` property validation."""
return keyword in (
'flex-start', 'flex-end', 'center', 'space-between', 'space-around')
@validator(unstable=True)
@single_keyword
def image_rendering(keyword):

View File

@ -316,7 +316,7 @@ def flex_layout(context, box, max_position_y, skip_stack, containing_block,
# Step 12
free_space = available_main_space - sum(
child.width for line in flex_lines for child in line)
child.margin_width() for line in flex_lines for child in line)
if free_space:
margins = 0
@ -326,20 +326,33 @@ def flex_layout(context, box, max_position_y, skip_stack, containing_block,
margins += 1
if child.margin_right == 'auto':
margins += 1
if margins:
free_space /= margins
else:
free_space = 0
for line in flex_lines:
for child in line:
if child.margin_left == 'auto':
child.margin_left = free_space
if child.margin_right == 'auto':
child.margin_right = free_space
for line in flex_lines:
# TODO: handle rtl
position_x = box.content_box_x()
if box.style['justify_content'] == 'flex-end':
position_x += free_space
elif box.style['justify_content'] == 'center':
position_x += free_space / 2
elif box.style['justify_content'] == 'space-around':
position_x += free_space / len(line) / 2
for child in line:
if child.margin_left == 'auto':
child.margin_left = free_space
if child.margin_right == 'auto':
child.margin_right = free_space
child.position_x = position_x
position_x += child.margin_width()
if box.style['justify_content'] == 'space-around':
position_x += free_space / len(line)
elif box.style['justify_content'] == 'space-between':
if len(line) > 1:
position_x += free_space / (len(line) - 1)
# TODO: align according to justify-content