Skip to content

Commit

Permalink
Deduplicate flex logic for rtl
Browse files Browse the repository at this point in the history
Related to #1225.
  • Loading branch information
liZe committed Oct 21, 2020
1 parent f5f204e commit 638b70e
Showing 1 changed file with 30 additions and 53 deletions.
83 changes: 30 additions & 53 deletions weasyprint/layout/flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def flex_layout(context, box, max_position_y, skip_stack, containing_block,
not_collected_items = []
for i, child in line:
align_self = child.style['align_self']
if (box.style['flex_direction'].startswith('row') and
if (axis == 'width' and
align_self == 'baseline' and
child.margin_top != 'auto' and
child.margin_bottom != 'auto'):
Expand Down Expand Up @@ -649,62 +649,39 @@ def flex_layout(context, box, max_position_y, skip_stack, containing_block,
child.margin_bottom = free_space
free_space = 0

if (box.style['direction'] == 'rtl' and
box.style['flex_direction'].startswith('row')):
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' and axis == 'width':
free_space *= -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
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
margin_axis = (
child.margin_width() if axis == 'width'
else child.margin_height())
if box.style['direction'] == 'rtl' and axis == 'width':
margin_axis *= -1
position_axis += margin_axis
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)

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'
Expand Down

0 comments on commit 638b70e

Please sign in to comment.