Skip to content

Commit

Permalink
Merge pull request #1389 from ColinKinloch/text_align_last
Browse files Browse the repository at this point in the history
Add text-align-last
  • Loading branch information
liZe committed Aug 24, 2021
2 parents 61ff7f0 + f586992 commit 7192030
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions weasyprint/css/properties.py
Expand Up @@ -148,6 +148,7 @@
'letter_spacing': 'normal',
'tab_size': 8,
'text_align': 'start',
'text_align_last': 'auto',
'text_indent': Dimension(0, 'px'),
'text_transform': 'none',
'white_space': 'normal',
Expand Down Expand Up @@ -258,6 +259,7 @@
'quotes',
'tab_size',
'text_align',
'text_align_last',
'text_decoration_line',
'text_decoration_color',
'text_decoration_style',
Expand Down
7 changes: 7 additions & 0 deletions weasyprint/css/validation/properties.py
Expand Up @@ -1101,6 +1101,13 @@ def text_align(keyword):
return keyword in ('left', 'right', 'center', 'justify', 'start', 'end')


@property()
@single_keyword
def text_align_last(keyword):
"""``text-align-last`` property validation."""
return keyword in ('auto', 'left', 'right', 'center', 'justify', 'start', 'end')


@property()
def text_decoration_line(tokens):
"""``text-decoration-line`` property validation."""
Expand Down
8 changes: 6 additions & 2 deletions weasyprint/layout/inlines.py
Expand Up @@ -1316,15 +1316,19 @@ def text_align(context, line, available_width, last):
return 0

align = line.style['text_align']
align_last = line.style['text_align_last']
if last:
if align_last != 'auto':
align = align_last
elif align == 'justify':
align = 'start'
space_collapse = line.style['white_space'] in (
'normal', 'nowrap', 'pre-line')
if align in ('left', 'right'):
if (align == 'left') ^ (line.style['direction'] == 'rtl'):
align = 'start'
else:
align = 'end'
if align == 'justify' and last:
align = 'start'
if align == 'start':
return 0
offset = available_width - line.width
Expand Down

0 comments on commit 7192030

Please sign in to comment.