diff --git a/tests/test_presentational_hints.py b/tests/test_presentational_hints.py index bd7e1a1b18..b47117f4f5 100644 --- a/tests/test_presentational_hints.py +++ b/tests/test_presentational_hints.py @@ -64,12 +64,12 @@ def test_ph_flow(): body, = html.children pre, center, div1, div2, div3, div4, div5 = body.children assert pre.style['white_space'] == 'pre-wrap' - assert center.style['text_align'] == 'center' - assert div1.style['text_align'] == 'center' - assert div2.style['text_align'] == 'center' - assert div3.style['text_align'] == 'left' - assert div4.style['text_align'] == 'right' - assert div5.style['text_align'] == 'justify' + assert center.style['text_align_all'] == 'center' + assert div1.style['text_align_all'] == 'center' + assert div2.style['text_align_all'] == 'center' + assert div3.style['text_align_all'] == 'left' + assert div4.style['text_align_all'] == 'right' + assert div5.style['text_align_all'] == 'justify' @assert_no_logs @@ -222,11 +222,11 @@ def test_ph_tables(): assert td.style['border_top_width'] == 1 assert td.style['border_top_style'] == 'inset' h1, p = td.children - assert h1.style['text_align'] == 'right' - assert p.style['text_align'] == 'center' + assert h1.style['text_align_all'] == 'right' + assert p.style['text_align_all'] == 'center' foot, = foot_group.children tr, = foot.children - assert tr.style['text_align'] == 'justify' + assert tr.style['text_align_all'] == 'justify' @assert_no_logs diff --git a/tests/test_text.py b/tests/test_text.py index f4f138dd53..367c8260b0 100644 --- a/tests/test_text.py +++ b/tests/test_text.py @@ -244,6 +244,86 @@ def test_text_align_justify(): assert image_5.position_x == 0 +@assert_no_logs +def test_text_align_justify_all(): + page, = render_pages(''' + +
+
+
+
+
+
''')
+ html, = page.children
+ body, = html.children
+ paragraph, = body.children
+ line_1, line_2 = paragraph.children
+ image_1, space_1, strong = line_1.children
+ image_2, space_2, image_3, space_3, image_4 = strong.children
+ image_5, space_4, image_6 = line_2.children
+ assert space_1.text == ' '
+ assert space_2.text == ' '
+ assert space_3.text == ' '
+ assert space_4.text == ' '
+
+ assert image_1.position_x == 0
+ assert space_1.position_x == 40
+ assert strong.position_x == 70
+ assert image_2.position_x == 70
+ assert space_2.position_x == 130
+ assert image_3.position_x == 160
+ assert space_3.position_x == 170
+ assert image_4.position_x == 200
+ assert strong.width == 230
+
+ assert image_5.position_x == 0
+ assert space_4.position_x == 200
+ assert image_6.position_x == 290
+
+
+@assert_no_logs
+def test_text_align_all_last():
+ page, = render_pages('''
+
+
+
+
+
+
''')
+ html, = page.children
+ body, = html.children
+ paragraph, = body.children
+ line_1, line_2 = paragraph.children
+ image_1, space_1, strong = line_1.children
+ image_2, space_2, image_3, space_3, image_4 = strong.children
+ image_5, image_6 = line_2.children
+ assert space_1.text == ' '
+ assert space_2.text == ' '
+ assert space_3.text == ' '
+
+ assert image_1.position_x == 0
+ assert space_1.position_x == 40
+ assert strong.position_x == 70
+ assert image_2.position_x == 70
+ assert space_2.position_x == 130
+ assert image_3.position_x == 160
+ assert space_3.position_x == 170
+ assert image_4.position_x == 200
+ assert strong.width == 230
+
+ assert image_5.position_x == 90
+ assert image_6.position_x == 290
+
+
@assert_no_logs
def test_text_align_not_enough_space():
page, = render_pages('''
diff --git a/weasyprint/css/properties.py b/weasyprint/css/properties.py
index 21e75537b5..9f2ee2566c 100644
--- a/weasyprint/css/properties.py
+++ b/weasyprint/css/properties.py
@@ -147,7 +147,7 @@
'hyphens': 'manual',
'letter_spacing': 'normal',
'tab_size': 8,
- 'text_align': 'start',
+ 'text_align_all': 'start',
'text_align_last': 'auto',
'text_indent': Dimension(0, 'px'),
'text_transform': 'none',
@@ -258,7 +258,7 @@
'overflow_wrap',
'quotes',
'tab_size',
- 'text_align',
+ 'text_align_all',
'text_align_last',
'text_decoration_line',
'text_decoration_color',
diff --git a/weasyprint/css/validation/expanders.py b/weasyprint/css/validation/expanders.py
index d5ef2a0eb7..937cfbb031 100644
--- a/weasyprint/css/validation/expanders.py
+++ b/weasyprint/css/validation/expanders.py
@@ -639,3 +639,16 @@ def expand_line_clamp(base_url, name, tokens):
raise InvalidValues
else:
raise InvalidValues
+
+
+@expander('text-align')
+def expand_text_align(base_url, name, tokens):
+ """Expand the ``text-align`` property."""
+ if len(tokens) == 1:
+ keyword = get_single_keyword(tokens)
+ align_all = 'justify' if keyword == 'justify-all' else keyword
+ yield 'text_align_all', align_all
+ align_last = 'start' if keyword == 'justify' else align_all
+ yield 'text_align_last', align_last
+ else:
+ raise InvalidValues
diff --git a/weasyprint/css/validation/properties.py b/weasyprint/css/validation/properties.py
index 456b379afe..295a3658a4 100644
--- a/weasyprint/css/validation/properties.py
+++ b/weasyprint/css/validation/properties.py
@@ -1096,8 +1096,8 @@ def table_layout(keyword):
@property()
@single_keyword
-def text_align(keyword):
- """``text-align`` property validation."""
+def text_align_all(keyword):
+ """``text-align-all`` property validation."""
return keyword in ('left', 'right', 'center', 'justify', 'start', 'end')
diff --git a/weasyprint/layout/inlines.py b/weasyprint/layout/inlines.py
index 25cbbbe424..f34fe3a6ae 100644
--- a/weasyprint/layout/inlines.py
+++ b/weasyprint/layout/inlines.py
@@ -1315,13 +1315,10 @@ def text_align(context, line, available_width, last):
if line.width >= available_width:
return 0
- align = line.style['text_align']
+ align = line.style['text_align_all']
if last:
align_last = line.style['text_align_last']
- if align_last != 'auto':
- align = align_last
- elif align == 'justify':
- align = 'start'
+ align = align if align_last == 'auto' else align_last
space_collapse = line.style['white_space'] in (
'normal', 'nowrap', 'pre-line')
if align in ('left', 'right'):