From 1e35ab3c5e499146d7ada78b2bb427af4e4236af Mon Sep 17 00:00:00 2001 From: "Mohammed Y. Alnajdi" Date: Sat, 3 Oct 2020 20:42:36 +0300 Subject: [PATCH] flexbox: initial attempt to support flex with rtl --- weasyprint/layout/flex.py | 74 +++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/weasyprint/layout/flex.py b/weasyprint/layout/flex.py index 3d610a50..5fc95dc6 100644 --- a/weasyprint/layout/flex.py +++ b/weasyprint/layout/flex.py @@ -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'