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

flexbox: initial attempt to support flex with rtl

This commit is contained in:
Mohammed Y. Alnajdi 2020-10-03 20:42:36 +03:00
parent 251157944e
commit 1e35ab3c5e

View File

@ -650,33 +650,61 @@ def flex_layout(context, box, max_position_y, skip_stack, containing_block,
child.margin_bottom = free_space
free_space = 0
if justify_content == 'flex-end':
position_axis += free_space
elif justify_content == 'center':
position_axis += free_space / 2
elif justify_content == 'space-around':
position_axis += free_space / len(line) / 2
elif justify_content == 'space-evenly':
position_axis += free_space / (len(line) + 1)
if box.style['direction'] == 'rtl':
if justify_content == 'flex-end':
position_axis -= free_space
elif justify_content == 'center':
position_axis -= free_space / 2
elif justify_content == 'space-around':
position_axis -= free_space / len(line) / 2
elif justify_content == 'space-evenly':
position_axis -= free_space / (len(line) - 1)
for i, child in line:
if axis == 'width':
child.position_x = position_axis
if justify_content == 'stretch':
child.width += free_space / len(line)
else:
child.position_y = position_axis
position_axis += (
child.margin_width() if axis == 'width'
else child.margin_height())
if justify_content == 'space-around':
position_axis += free_space / len(line)
elif justify_content == 'space-between':
if len(line) > 1:
position_axis += free_space / (len(line) - 1)
for i, child in line:
if axis == 'width':
child.position_x = position_axis
if justify_content == 'stretch':
child.width -= free_space / len(line)
else:
child.position_y = position_axis
position_axis -= (
child.margin_width() if axis == 'width'
else child.margin_height())
if justify_content == 'space-around':
position_axis -= free_space / len(line)
elif justify_content == 'space-between':
if len(line) > 1:
position_axis -= free_space / (len(line) + 1)
elif justify_content == 'space-evenly':
position_axis -= free_space / (len(line) - 1)
else:
if justify_content == 'flex-end':
position_axis += free_space
elif justify_content == 'center':
position_axis += free_space / 2
elif justify_content == 'space-around':
position_axis += free_space / len(line) / 2
elif justify_content == 'space-evenly':
position_axis += free_space / (len(line) + 1)
for i, child in line:
if axis == 'width':
child.position_x = position_axis
if justify_content == 'stretch':
child.width += free_space / len(line)
else:
child.position_y = position_axis
position_axis += (
child.margin_width() if axis == 'width'
else child.margin_height())
if justify_content == 'space-around':
position_axis += free_space / len(line)
elif justify_content == 'space-between':
if len(line) > 1:
position_axis += free_space / (len(line) - 1)
elif justify_content == 'space-evenly':
position_axis += free_space / (len(line) + 1)
# Step 13
position_cross = (
box.content_box_y() if cross == 'height'